Classic ASP and Server.GetLastError in IIS7

My classic ASP error logging scripts were dead in the water when I moved them to a Windows Server 2008 with IIS 7.0.

Some code like this is useful to record errors in a database:

dim objErrorInfo, errorStringStr
set objErrorInfo = Server.GetLastError
errorStringStr = objErrorInfo.File & ", line: " & objErrorInfo.Line & ", error: " & objErrorInfo.Number & " " & objErrorInfo.Description & ", " & objErrorInfo.ASPDescription & objErrorInfo.Category
errorStringStr = replace( errorStringStr, "'", "''" )

The error pages settings are less convenient than in the previous version of IIS for classic ASP developers. If you would like to use different scripts to handle 404 and 500 errors access Server.GetLastError, I do not believe a classic ASP solution can get the job done. Alas, I figured out how to get the full contents of Server.GetLastError in IIS7 (using one script).

Create one script to log all errors. If you had a few scripts to handle different types of errors, combine them.

Enter the Error Pages module of the website profile, and click “Edit Feature Settings” on the right hand sidebar.

This screen will appear:

Edit Error Pages Settings

Configure yours in a similar fashion, and Server.GetLastError will start working once again. Ignore the settings that allow you to choose a custom URL for each HTTP status code. This setting alone will send all error responses through your script.

UPDATE:

I was mistaken about using multiple scripts to log errors. The only way to get the contents of Server.GetLastError is to use the “Edit Feature Settings” section of the Error Pages control. The other error pages will work, but Server.GetLastError is not available. For example, I just added a status code for 410 Gone to a website using the custom script I describe above. I am not interested in logging 410 errors in my database, so simply adding the 410 status code to point to C:\inetpub\custerr\en-US\410.htm works. As a side note, my Windows 2008 Server Web did not have the 410.htm. I copied it from a Windows 2003 Server installation.

6 Comments so far

  1. rick on August 27th, 2009

    It worked. I wonder why edit feature settings works differently than doubleclicking the script.

  2. Rowdy on November 3rd, 2009

    This is a work-around.
    The real solution is to go to the Error Pages in IIS7, click Add… and add a handler for error code 500.100 and point that to /error.asp.

  3. ares on December 20th, 2009

    Adding handler for error code 500.100 and point that to /error.asp. … Thats works great for me .

    Thanks

  4. Simon on January 2nd, 2010

    “The real solution is to go to the Error Pages in IIS7, click Add… and add a handler for error code 500.100 and point that to /error.asp”

    Can this be done from web.config file?

  5. Simon on January 2nd, 2010

    <?xml version="1.0" encoding="UTF-8"?><configuration> <system.webServer> <httpErrors> <remove statusCode="500" subStatusCode="100" /> <error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/error-500.asp" responseMode="ExecuteURL" /> </httpErrors> </system.webServer></configuration>

  6. Corey on January 2nd, 2010

    Thanks for the tip on 500.100. I will give it a shot.

Leave a reply

 

Thanks for reading!

You like? Subscribe to my rss feed
or

Sign up for email updates:

Some Recent Updates