Error Trapping in ASP.NET
Posted on 2005-03-15
I am creating a ASP.NET application. I want to log any errors that occur into the event log. I am using the Microsoft.ApplicationBlocks.ExceptionManagement component for accomplishing that. When the error occurs, I also want to redirect to custom error page.
Here is what I did:
In the global.asax
protected void Application_Error(Object sender, EventArgs e)
Exception objErr = Server.GetLastError().GetBaseException();
In the web.config
<customErrors mode="Off" defaultRedirect="ErrorPage.aspx" />
In the Page_Load event, I throw an error
private void Page_Load(object sender, System.EventArgs e)
Throw an error...
When I execute this, the error message gets logged in the eventlog, but the page never gets redirected to the Error page. I can't figure out what's going on here.
Also, should I avoid using try catch blocks throughout my code and let the Application_Error event catch it? I'm not sure if there's a rule of thumb when it comes to error handling in ASP .NET.