Saturday, June 30, 2007

Importance of Custom Error Pages

Custom Error Pages are static/dynamic pages which a commercial site deploys in case of an error (404 - page not found error/ database error / etc). A site may be designed beautifully with colourful themes and user-friendly navigation tabs but it must be ensured that a page, like the one which follows, does not come up on screen in case the site breaks.

A custom error page would have been less embarrassing here for marvel.com

Taking the example of Microsoft's ASP.NET, displaying the custom error page 'error.html' is as easy as modifying the Application_Error event (which gets called in case of an unhandled error occurring in the application) in global.asax :


protected void Application_Error(object sender, EventArgs e)
{
   Response.Redirect("error.html");
}


Ofcourse, this is not the only way to implement custom errors in ASP.NET, but in my humble opinion, is the easiest. Also, error logging can be done by including the relevant logging code in the same event before the Redirect statement.

This would ensure that the look and feel of your site remains consistent, even at the time of a crucial error.

2 comments:

Tarun Kohli said...

Nitin,

You mentioned that error logging could be done at this event level. I was wondering should the error logging be done at source or in an event like this? Furthermore, what kind of logging framework would you suggest to log these exceptions log4Net or Enterprise Logging Application block?

GrasshopperBoy said...

Hi Tarun,

IMHO, error logging could be done at this level with the help of system/custom exceptions eliminating the need to do so at source. This would enable better encapsulation of the logging framework.

As for the logging frameworks, I'm going to have to get back at you with that. :)