Catching ASP.NET errors

  • Thread starter Thread starter Mikael Engdahl
  • Start date Start date
M

Mikael Engdahl

Hello,

When an unhandled exception occurs on an ASP.NET page, a well known page
will appear, having the header "Server Error in '[app path]' Application"
and the Exception Details and Stack Trace below it.

Is it possible to customize this page and for example save to exception
info in a database and display a custom message to the user.

Does anybody know if this is possible?
 
There is an Error event in the page class. If you handle it, you can do
whatever you want, including making sure that this error page never displays
at all.

There is also an Application_Error event in Global.asax, which handles
unhandled errors from the entire application.
 
I would recommend writing your own page class that will handle the errors
experience on every page. It saves you from having to put the
Page.OnError() method of every page.

I used to use Application_OnError but I could consistently have access to
the session variables that held user information, and I was trying to catch
the sql query used that crashed the page (usually that is where the
Exceptions are for my project).

bill
 
Back
Top