Creating custom error pages in ASP.NET

20Apr11

How many times have you been in a client demo when your application throws an ugly stack trace up on the screen? Double points if it is up on the projector at about eight feet wide.

Now, I don’t like to go overboard with excessive exception handling just to avoid the appearance of errors, but there is one thing that we can do easily that will still allow us to avoid swallowing exceptions all over and it is as easy as putting a few lines into your web.config.

<system.web>
    <customErrors mode="On" defaultRedirect="Error.aspx"/>
    ...
</system.web>

This will redirect the browser to Error.aspx on any unhandled exception in the application. We can still do some error logging by looking at the results of:

Server.GetLastError()

Here are some more details about getting error details in the custom error page.

Advertisements


No Responses Yet to “Creating custom error pages in ASP.NET”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: