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:

iis7getLastError

Configure yours in a similar fashion, and Server.GetLastError will start working in your script.

19 comments

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

  2. 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. “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?

  4. <?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>

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

    I’m happy :-)

  6. 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!!!

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

  8. “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.

  9. “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!

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

  11. Thanks for this post, it saved my day! Following is the specific web.config setup that worked for me, in IIS7.x

    Note that existingResponse MUST be “Auto”. It won’t work if you use “Replace”.

  12. Thanks again to Simon for the info about redirecting via the web.config file. Worked great and didn’t have to hassle with the hosting service to change anything. For anyone who happens to be searching this topic, I changed this line:

    to this:

    In ErrorReport.asp I included this:

    set objErr=Server.GetLastError()

    along with some code like:

    response.write(“File=” & objErr.File)
    response.write(“”)
    response.write(“Line=” & objErr.Line)

Leave a comment

Your email address will not be published. Required fields are marked *