You can use the ASPError object to obtain information about an error condition that has occurred in script in na ASP page. The ASPError object is returned by the Server.GetLastError method. The ASPError object exposes read-only properties.
ASPError.property
ASPCode | Returns an error code generated by IIS |
Number | Returns the standard COM error code |
Source | Returns the actual source code, when available, of the line that caused the error |
Category | Indicates if the source of the error was internal to ASP, the scripting language, or an object |
File | Indicates the name of the .asp file that was being processed when the error occurred |
Line | Indicates the line within the .asp file that generated the error |
Column | Indicates the column position within the .asp file that generated the error |
Description | Returns a short description of the error |
ASPDescription | Returns a more detailed description of the error if it is an ASP-related error |
When IIS encounters an error either with compiling or running an .asp file, it will generate a 500;100 custom error. By default all Web sites and applications will transfer processing of a 500;100 custom error to the default .asp file. After a 500;100 custom error is generated, IIS will also create an instance of the ASPError object which describes the error condition.
The following example, extracted from the file 500-100.asp, demonstrates writing the information exposed by the ASPError object.
<%
Response.Write objASPError.Category
If objASPError.ASPCode > "" Then Response.Write ", " & objASPError.ASPCode
Response.Write " (0x" & Hex(objASPError.Number) & ")" & "<br>"
Response.Write "<b>" & objASPError.Description & "</b><br>"
If objASPError.ASPDescription > "" Then Response.Write objASPError.ASPDescription & "<br>"
blnErrorWritten = False
' Only show the Source if it is available and the request is from the same machine as IIS
If objASPError.Source > "" Then
strServername = LCase(Request.ServerVariables("SERVER_NAME"))
strServerIP = Request.ServerVariables("LOCAL_ADDR")
strRemoteIP = Request.ServerVariables("REMOTE_ADDR")
If (strServername = "localhost" Or strServerIP = strRemoteIP) And objASPError.File <> "?" Then
Response.Write objASPError.File
If objASPError.Line > 0 Then Response.Write ", line " & objASPError.Line
If objASPError.Column > 0 Then Response.Write ", column " & objASPError.Column
Response.Write "<br>"
Response.Write "<font style=""COLOR:000000; FONT: 8pt/11pt courier new""><b>"
Response.Write Server.HTMLEncode(objASPError.Source) & "<br>"
If objASPError.Column > 0 Then Response.Write String((objASPError.Column - 1), "-") & "^<br>"
Response.Write "</b></font>"
blnErrorWritten = True
End If
End If
If Not blnErrorWritten And objASPError.File <> "?" Then
Response.Write "<b>" & objASPError.File
If objASPError.Line > 0 Then Response.Write ", line " & objASPError.Line
If objASPError.Column > 0 Then Response.Write ", column " & objASPError.Column
Response.Write "</b><br>"
End If
%>