Delphi Clinic C++Builder Gate Kylix Kicks JBuilder Machine Delphi for .NET
Dr.Bob's Delphi Notes Dr.Bob's Delphi Clinics
 Dr.Bob Examines... #94
See Also: Dr.Bob's Delphi Papers and Columns

ASP.NET Error Handling
In this article, I'll explain the foundations of ASP.NET error handling, applicable to both ASP.NET 1.1 and ASP.NET 2.0 web applications.

ASP.NET Error Handling consists of catching the error and handling it or at least preventing it from displaying a very ugly error message page to the end user. This also means that we should put user-friendly error messages on screen, but specific, technical error messages on some place where we can examine them - either via a browser or in a logfile or e-mail message.
For the error specifics, I prefer to use the ASP.NET Trace object, with the Write and Warn methods (Warn is the same as Write, but the text is displayed in a red font in the trace window). Page vs. Application Trace.axd requestLimit (last!)Trace.TraceFinished (new ASP.NET 2.0 event)

Method Specific
The first way to detect and try to handle errors in ASP.NET application is the method specific way; inside each method, we should place a try-except block, placing the original code in the try clause and handling the error in the except clause. This sounds like a lot of work, but it will be worth it in the end.
Try-ExceptException GetType InnerException Message Source StackTrace TargetSite

Page Specific
Page.ErrorServer.GetLastErrorServer.ClearError

Application Specific
Global.asax/.pasApplication_Error

Site Specific
web.config <customerrors mode="RemoteOnly" (on / off) defaultredirect=""> <error statuscode="statusCode" redirect="url" /> </customerrors>No Server.GetLastErrorSolution: SessionWarning: Make sure session is used !!!


This webpage © 2008 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.