Classic ASP - Trap 500 Errors

I am trying to diagnose a problem with a site that seems to be causing a code error somewhere. From the error logs, it seems SQL syntax error caused by poor concatenation of SQL query with bad code. My problem is that I cannot reproduce the error, but the clients are still getting it, and this may be the reason for several requests. So my plan is to create my own 500 error page to catch the result.

I want the page to catch all session data, all POST and GET data (what can I do), but I also want to get detailed error information. Quite a lot of what will be displayed on the page when the site allows you to display errors. With a small arrow indicating a line.

Is there a way to catch an error on a custom 500 error page?

Thanks in advance

Grant

+8
iis iis-7 asp-classic
source share
2 answers

You can get good, but not much information from the ASP when you have a bug.

But you can define a custom 500-page ASP error code page that can give you a bit more information when your program crashes. Here is an example of code that will produce a pretty decent error message.

Set objASPError = Server.GetLastError Dim strProblem strProblem = "ASPCode: " & Server.HTMLEncode(objASPError.ASPCode) & vbCrLf strProblem = strProblem & "Number: 0x" & Hex(objASPError.Number) & vbCrLf strProblem = strProblem & "Source: [" & Server.HTMLEncode(objASPError.Source) & "]" & vbCrLf strProblem = strProblem & "Category: " & Server.HTMLEncode(objASPError.Category) & vbCrLf strProblem = strProblem & "File: " & Server.HTMLEncode(objASPError.File) & vbCrLf strProblem = strProblem & "Line: " & CStr(objASPError.Line) & vbCrLf strProblem = strProblem & "Column: " & CStr(objASPError.Column) & vbCrLf strProblem = strProblem & "Description: " & Server.HTMLEncode(objASPError.Description) & vbCrLf strProblem = strProblem & "ASP Description: " & Server.HTMLEncode(objASPError.ASPDescription) & vbCrLf strProblem = strProblem & "Server Variables: " & vbCrLf & Server.HTMLEncode(Request.ServerVariables("ALL_HTTP")) & vbCrLf strProblem = strProblem & "QueryString: " & Server.HTMLEncode(Request.QueryString) & vbCrLf strProblem = strProblem & "URL: " & Server.HTMLEncode(Request.ServerVariables("URL")) & vbCrLf strProblem = strProblem & "Content Type: " & Server.HTMLEncode(Request.ServerVariables("CONTENT_TYPE")) & vbCrLf strProblem = strProblem & "Content Length: " & Server.HTMLEncode(Request.ServerVariables("CONTENT_LENGTH")) & vbCrLf strProblem = strProblem & "Local Addr: " & Server.HTMLEncode(Request.ServerVariables("LOCAL_ADDR")) & vbCrLf strProblem = strProblem & "Remote Addr: " & Server.HTMLEncode(Request.ServerVariables("LOCAL_ADDR")) & vbCrLf strProblem = strProblem & "Time: " & Now & vbCrLf 

Edit In IIS7 GetLastError, there seems to be no information.
You can solve this problem by creating 500.100 and pointing this to your script.
YMMV, check these URLS for more information http://forums.iis.net/t/1150502.aspx and http://www.tacticaltechnique.com/web-development/classic-asp-getlasterror-in-iis7/

+14
source share

Usually you set "on error resume next" and then check the error code "Err.Number" after the line breaking the code for non-zero values.

See: http://www.powerasp.com/content/new/on-error-resume-next.asp

+3
source share

All Articles