New MSDN article: Rich Custom Error Handling

There are a lot of bytes online about handling exceptions in ASP.NET. This article presents a solution you can have running in an hour or two. From the introduction:

“An ideal error page maintains the look and feel of the site, offers the ability to provide detailed errors to internal developers — identified by IP address — and at the same time offers no detail to end users. Instead, it gets them back to what they were seeking — easily and without confusion. The site administrator should be able to review errors encountered either by e-mail or in the server logs, and optionally be able to receive feedback from users who run into trouble. Is this the stuff of dreams? No more.”

The downloadable source code found in the article produces this sort of screen when hit by the developer (i.e. from an IP address in the specified range -- you're no longer limited to localhost!).

Fjorbes Error screen shot

I use this implementation on erobillard.com, you can check it out by triggering a 404. The difference between this and the Fjorbes demo is that you, the end-user won't see any detail about the error on my site.

It took me about an hour to install the article's code on my site (but then I wrote it), most of this time was spent modifying the custom error page -- point to a different .css, customize the header and graphic, etc. First-time configuration is pretty quick, it should only take 5-15 minutes for most people.

Read the article. 

Published Wednesday, January 28, 2004 12:17 PM by erobillard

Comments

Wednesday, January 28, 2004 12:42 PM by TrackBack

# MSDN: Rich Custom Error Handling

Saturday, February 14, 2004 11:50 PM by TrackBack

# Reusable Error Dialog for .NET

Wednesday, March 03, 2004 4:54 PM by Bob Cooley

# re: New MSDN article: Rich Custom Error Handling

I have been playing around with your sample app, and I love all of the information it displays. I was wondering however if ther is a way to write all of the information that it displays on the web page to a file for viewing later?

Thanks!
Bob Cooley
Saturday, March 06, 2004 2:08 PM by Eli Robillard

# re: New MSDN article: Rich Custom Error Handling

Hi Bob,

There are two common solutions -- writing to the event log and writing to a text file.

Writing to the event log is covered in Rob Howard's article:
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspnet/html/asp08232001.asp

There is an article on 15seconds.com which contains source to write an exception to a file:
http://www.15seconds.com/issue/030102.htm

Writing to a file is similar to writing to the log, you could copy the WriteErrorToLog() function found in the global.asax and write strError to a file instead of the event log. System.IO is already referenced, so all you need is something like:

Dim obj as StreamWriter
obj = File.AppendText( MapPath( "myLog.txt" ))
obj.WriteLine(strError)
obj.Close

Though hard-coded paths should be avoided -- ideally you would configure the "myLog.txt" bit with an entry in appSettings, the same way the Rich Custom Error Handler is configured.

Take care,
Eli.
Wednesday, July 21, 2004 8:37 PM by Trevor Lawrence

# re: New MSDN article: Rich Custom Error Handling

Your article says that when storing error information in the Session object, you cannot use Response.Redirect to get to your error page. Why do you say that? The session is not destroyed on a redirect. My implementation using Session and Redirect seems to work fine.
Wednesday, June 27, 2007 9:28 AM by Michael Freidgeim

# re: New MSDN article: Rich Custom Error Handling

Funny to note, but 3 years later I am asking the same question: why Response.Redirect()  can't use Session as storage basket?

Friday, July 20, 2007 8:31 AM by Michael Freidgeim

# re: New MSDN article: Rich Custom Error Handling

In my post <a href="geekswithblogs.net/.../Passing-Exception-details-in-Session-to-Custom-Error-page.aspx">"Passing Exception details in Session to Custom Error page." </a> I wrote how to use Redirect with Session

Leave a Comment

(required) 
(required) 
(optional)
(required)