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:
Configure yours in a similar fashion, and Server.GetLastError will start working in your script.
Comments
20 responses to “Classic ASP and Server.GetLastError in IIS7”
It worked. I wonder why edit feature settings works differently than doubleclicking the script.
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.
Adding handler for error code 500.100 and point that to /error.asp. … Thats works great for me .
Thanks
“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?
<?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>
Thanks for the tip on 500.100. I will give it a shot.
Thanks Simon, i have been nagging my host for this for days now to no avail.
You are a star man, keep shining!
The 500.100 made it! Thanks to Rowdy.
Thanks to the original poster, too, allowing me to find this thing.
I’m happy :-)
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!!!
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
“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.
500.100 worked !! Thanks a lot.
“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!
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
This did the trick for me. Thanks so much!
“add a handler for error code 500.100”
Worked for me, many thanks
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”.
It took me about 6 months off and on to find this. It wasn’t until I added the handler for 500.100 that I finally got it to work.
So thanks very much for that!
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)
Thanks to Simon for his 12 year old tip. subStatusCode=”100? on a 500 error than “-1” fixed my problem of redirecting and maintaining accurate error data captured in Server.GetLastError() for logging/email/notification purposes, whilst maintaining browser privacy for the client.