I want to know which parts of the ASP.NET request life cycle happen after an error is handled via the HttpApplication.Error event. Specifically, which of the events listed at http://msdn.microsoft.com/en-us/library/bb470252.aspx#Stages fire after an error? I know that EndRequest still fires, and I suspect that PreSendRequestHeaders and PreSendRequestContent fire as well, but aside from these I have no idea.
Does it depend on when in the life cycle the error occurs? Does it depend on whether I call Server.ClearError() in the error handler?
I'm asking this question because I don't know if I should be calling HttpApplication.CompleteRequest() from my error handler.
Init. This event fires after each control has been initialized. Each control's UniqueID is set and any skin settings have been applied. Use this event to read or initialize control properties.
UnLoad - The UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed.
In ASP.NET, a web page has execution lifecycle that includes various phases. These phases include initialization, instantiation, restoring and maintaining state etc. it is required to understand the page lifecycle so that we can put custom code at any stage to perform our business logic.
The Viewstate is actually loaded in the OnPreLoad event of the page,Just after the Page_InitComplete.
The best way is to catch server last error and appdomain exceptions.
All of them can be done in Global.asax.cs file.
Check the following steps:
1- In Global.asax.cs, catch the last error and log it.
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Server.ClearError();
log.Error("Application Error caught in Global ", exception);
}
2- Add an event handler for UnhandledException event on AppDomain, this should be added to the Application_Start :
protected void Application_Start(object sender, EventArgs e)
{
//....
AppDomain.CurrentDomain.UnhandledException
+= new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
3- And here is the implementation of CurrentDomain_UnhandledException:
void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
if (e != null)
log.Error("Domain Unhandled Exception: ", e.ExceptionObject as Exception);
}
Happy coding :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With