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, "'", "''" )

Instead of using the default 500 item in the list, create a new handler for status code 500.100. Point this at your script, and you should be all set to log errors.

Another way is to 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 in your script.

14 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.

  7. blestab on February 7th, 2011

    Thanks Simon, i have been nagging my host for this for days now to no avail.

    You are a star man, keep shining!

  8. Andreas on June 7th, 2011

    The 500.100 made it! Thanks to Rowdy.
    Thanks to the original poster, too, allowing me to find this thing.

    I’m happy :-)

  9. Jeff V on July 20th, 2011

    Another thumbs-up for this solution.

    My Hosting Provider had subStatusCode=”-1″ in web.config. I changed to subStatusCode=”100″ and it worked!

    THANK YOU!!!

  10. uwe on August 14th, 2011

    I updated my ASP application to IIS 7.0.6000, I edit a hanler for errors 500. The IIS jumps to this programm and writes all information in a text file. But everything like Line is null and not helpfull. What can I do? Please help!
    Thanks from Austria

  11. Yes Yes Yes on September 8th, 2011

    “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”

    That worked !!
    Great.

  12. Amit on October 7th, 2011

    500.100 worked !! Thanks a lot.

  13. Ravi on January 8th, 2012

    “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”

    That worked !!
    Great.
    Thanks a lot!

  14. Ravi on January 24th, 2012

    Hi,
    Few days before I added handler for error code 500.100 and point that to my asp error page /SMGRError.asp but and for some errors Server.GetLastError() is still not working.
    Please help me to fix this issue.Thanks, Ravi

Leave a reply

 

Thanks for reading!

Sign up for email updates: