Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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:

 

<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:

Never trouble another for what you can do for yourself.
  • 2 weeks later...
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...