Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
19 active users
18 visitors today
58 pages today
how is this done?
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

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

Tiki Statues - Tiki Masks - Tiki Totems



I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...

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?