Click here to Skip to main content
15,886,110 members
Articles / Web Development / IIS

User Friendly ASP.NET Exception Handling

Rate me:
Please Sign up or sign in to vote.
4.80/5 (70 votes)
20 Dec 20049 min read 667.4K   4.3K   344  
A flexible framework for user-friendly ASP.NET exception handling, and automatically notifying developers of problems before users do.
What is it?

This HTTP module implements global Unhandled Exception notification for any ASP.NET website, 
or any ASP.NET Web Service, without recompilation. When your application encounters an Unhandled 
Exception, you get the following for free:

 - a "user friendly" exception web page
 - an email notification 
 - a plain text logfile 
 - Event Log logging
 
How do I set it up?

This is the Quick Start. Refer to source headers for more options and details.

1) put ASPUnhandledException.dll in the /bin folder

2) Add these configuration options to the <appSettings> section of your Web.config

	<configSections>    
		<section name="UnhandledException" type="System.Configuration.NameValueSectionHandler, 
			System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
	</configSections>

	<UnhandledException>
  		<add key="EmailTo" value="me@domain.com;you@domain.com" />	
		<add key="ContactInfo" value="Ima TestGuy at 919-555-1212" />
		<add key="IgnoreRegex" value="get_aspx_ver\.aspx" />
		<add key="SmtpDefaultDomain" value="mydomain.com" />
		<add key="SmtpServer" value="mail.mydomain.com" />
	</UnhandledException>

3A) for an ASP.NET website, modify the <system.web> section of your Web.config

  <system.web>
	<!-- Adds our error handler to the HTTP pipeline -->
	<httpModules>
	  <add name="UehHttpModule" 
	       type="ASPUnhandledException.UehHttpModule, ASPUnhandledException" />
	</httpModules>
  </system.web>
  
2B) for an ASP.NET Web Service, modify the <webServices> section of your Web.config:

  <webServices>
	<!-- Adds our error handler to the SOAP pipeline -->
	<soapExtensionTypes>
	  <add type="ASPUnhandledException.UehSoapExtension, ASPUnhandledException"
	       priority="1" group="0" />
	</soapExtensionTypes>
  </webServices>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
My name is Jeff Atwood. I live in Berkeley, CA with my wife, two cats, and far more computers than I care to mention. My first computer was the Texas Instruments TI-99/4a. I've been a Microsoft Windows developer since 1992; primarily in VB. I am particularly interested in best practices and human factors in software development, as represented in my recommended developer reading list. I also have a coding and human factors related blog at www.codinghorror.com.

Comments and Discussions