ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Trapping HTTP 500.100 - Internal Server Error --> Part 2

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
137 active users
2956 visitors today
2885 pages today
(only part of today)
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

The Handle500100.asp file

The error handling file is just a normal ASP file. What makes it useful is the use of the Server.GetLastError() method to inform both the user and I (via email) what went wrong. We'll look at that code in a minute.

Just as when an HTTP 404, File not found error occurs, it is a very good idea to apologise profusely and offer your reader some options.

To see my handler in action, here's a link to the Test500100.asp file that contains the errors.

As you can see, I try to keep the user as happy as possible. The error page looks like any other page on the site, apologises and tries to keep the user from leaving the site in disgust.

The Server.GetLastError method

Microsoft JScript compilation
Syntax error
/cya/Test500100.asp, line 11

The handler wouldn't be very useful if it didn't tell me quickly what was wrong, so I can fix it. An example of the error I get is shown above, with the code to create it shown below:

(As always, you can get the entire source code by clicking on the icon at the end of the article).

var oASPError = Server.GetLastError ( );

var sError = '<p>' + oASPError.Category;

if ( oASPError.ASPCode > '' )
   sError += ', ' + oASPError.ASPCode;

sError += '<br><b>' + oASPError.Description + '</b><br>';

if (oASPError.ASPDescription > '' )
   sError += oASPError.ASPDescription + '<br>';

if ( oASPError.File != '?' )
{
   sError += '<b>' + oASPError.File;

   if ( oASPError.Line > 0 )
      sError += ', line ' + oASPError.Line;

   if ( oASPError.Column > 0 )
      sError += ', column ' + oASPError.Column;

   sError += '</b><br>';
}

Fairly self-explanatory I hope, and lifted almost verbatim from IIS's default 500 handler. Hey, it's going to work, right?

Part 3: Sending the email...

Featured sponsor
My favorite resources

Selling products online - read how James does it now


CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!