Global error provider

Mondeo

Centurion
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
Is there any way I can redirect to an error provider page whenever any exceptions occur on my site - by that I mean any that are not caught by Try/Catch blocks

Ideally i'd like a page called errorProvider.aspx which simply sends a copy of the execption to admin and displays a "sorry an error has occured" type message.

How is this scenario usually implemented?
 
web.config and global.asax

There are two steps here - displaying an error page to the user, and handling the exception and responding appropriately (logging the error, sending an email, etc). The error page can be set in the web.config file like so:

Code:
<system.web>
  <customErrors mode="On" defaultRedirect="errorProvider.aspx"/>
</system.web>

When an error occurs, the user will be redirected to errorProvider.aspx.

For the logging or emailing, you can implement this with a global.asax file, which is the successor to the global.asa file in ASP. This file contains code which can respond to application-level events, such as sessions starting and ending, requests starting and ending, and unhandled exceptions being thrown. The Application_Error event occurs when an unhandled exception occurs. This article explains enough to get you started.

Good luck :cool:
 
Just so you know, it's rarely mentioned, but between the method that threw the error and the global handler you can also override the Page OnError method so that you can handle errors for a page in a single location, sometimes you need something a little more fine grained than the global handler for a specific page.
 
Back
Top