Remind me please about custom error handling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am deep into a project and cannot get this to work correctly.
I am trying to make a custom error page that will be able to know what
exception occurred. I already know about the defaultRedirect page -

<customErrors mode="on" defaultRedirect="Error.aspx"/>

But how do I reference the exception that occurred from that page?
If I cant, then should I use the Application_Error event in global.asax ?
And if I do that, then what about hiding the error from the user?

Please tell me what I'm missing because I just cant see it now.
 
If you want to capture the exception, you can use Application_Error in
global.asax and use the Server.GetLastError to get the exception.
 
I would still like to redirect the user to another page and log that error.
I guess my question is how can I do both?
 
You can log the error message in Application_Error and then redirect the user
to the error page.
 
Right, but how will that page know the exception that occurred?
global.asax ... error event handler knows the exception from
server.GetLastError but the page wouldn't know the exception. Am I right?
 
Correct. That is why I told you to log your error in Application_Error via
Server.GetLastError and then have the user redirected to the error page that
just displays a typical "We're sorry, .......". If you handle your own error
in Application_Error and you have <customErrors> turned on, ASP.NET will
autotically redirect the user to the error page as long as you don't call
Server.ClearError in Application_Error. If you call Server.ClearError, they
you have to redirect the client to the error page yourself and you can pass
additional parameters to the page such as the actual error messsage.
 
Back
Top