[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
ASPFAQ_ErrorHandler
Back to ASP FAQ Main Page.
ASP Script error handler
This code is actually used on the Programmers Heaven WEBSITE to alert the WEBMASTER when an ASP-script error occurs. A comprehensive email is sent out for every script error and that give me a chance to fix those nasty bugs.
The email that is sent out contains all necessary information that you might need to find the cause of the error.
To install the script you need to redirect all server 500;100 errors to this script below. You do that redirection under the Custom Error tab in the IIS administration console. Select URL as message type and enter the relative path to the script below.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
ASPFAQ_ErrorHandler
Back to ASP FAQ Main Page.
ASP Script error handler
This code is actually used on the Programmers Heaven WEBSITE to alert the WEBMASTER when an ASP-script error occurs. A comprehensive email is sent out for every script error and that give me a chance to fix those nasty bugs.
The email that is sent out contains all necessary information that you might need to find the cause of the error.
To install the script you need to redirect all server 500;100 errors to this script below. You do that redirection under the Custom Error tab in the IIS administration console. Select URL as message type and enter the relative path to the script below.
<%
'Programmers Heaven ASP-script error handler
'http://www.programmersheaven.com
'
'(c) 2001 info@programmersheaven.com
'Please feel free to email comments on this code
'Turn on the error handling in case you get an error on this page
On Error Resume Next
dim sessitem,tmp,objError,strNumber,strCategory,strPage,strDesc
dim strCode, strLine,strASPDesc,Item,name,strColumn,strRemoteAddr
dim strRemoteHost,strLocalAddr,strQueryStr,strFormStr
'Referencing the error object
set objError = Server.getLastError()
'Returns the error code generated by IIS
strNumber = objError.AspCode
'Indicates if the source of the error was internal to ASP,
'the scripting language, or an object
strCategory = objError.Category
'Indicates the name of the .asp file that was being processed
'when the error occurred
strPage = objError.File
'Returns the actual source code, when available,
'of the line that caused the error
strCode = objError.Source
'Indicates the line within the .asp file that generated the error
strLine = ObjError.Line
'Indicates the column position within the .asp file that generated
'the error
strColumn=ObjError.Column
'Returns a short description of the error
strDesc = ObjError.Description
'Returns a more detailed description of the error
'if it is an ASP-related error
strASPDesc = ObjError.ASPDescription
'Get the IP adress of the user who got this errror
strRemoteAddr = Request.ServerVariables("REMOTE_ADDR")
'Get the name of the host making the request (if available).
strRemoteHost = Request.ServerVariables("REMOTE_HOST")
'Get the IP adress of the WEB-server that generated this error
strLocalAddr = Request.ServerVariables("LOCAL_ADDR")
'Get the entire QueryString
strQueryStr = Request.QueryString
'Get the entire form collection
strFormStr=Request.Form
If strCode = "" then
strCode = "No code available"
end if
'Build a error message email
tmp="Programmers Heaven ASP-script error handler" & vbcrlf & vbcrlf
tmp=tmp & "ErrorData" & vbcrlf
tmp=tmp & "Current Time:" & now & vbcrlf
tmp=tmp & "Error number:" & strNumber & vbcrlf
tmp=tmp & "Source:" & trim(strCategory) & vbcrlf
tmp=tmp & "Page:" & trim(strPage) & vbcrlf
tmp=tmp & "SourceCode:" & trim(strCode) & vbcrlf
tmp=tmp & "Line:" & trim(strLine) & vbcrlf
tmp=tmp & "Column:" & trim(strColumn) & vbcrlf
tmp=tmp & "Short Description:" & trim(strDesc) & vbcrlf
tmp=tmp & "Long Description:" & trim(strASPDesc) & vbcrlf
tmp=tmp & "Remote Address:" & trim(strRemoteAddr) & vbcrlf
tmp=tmp & "Remote Host:" & trim(strRemoteHost) & vbcrlf
tmp=tmp & "Local Address:" & trim(strLocalAddr) & vbcrlf
tmp=tmp & "Query string:" & trim(strQueryStr) & vbcrlf
tmp=tmp & "Form string" & trim(strFormStr) & vbcrlf
if request.QueryString.count>0 then
'Display all the items in the QueryString
tmp=tmp & vbcrlf & vbcrlf & "Querystring" & vbcrlf
For Each item In Request.QueryString
tmp=tmp & item & "=" & Request.QueryString(item) & vbcrlf
Next
end if
if request.form.count>0 then
'Display all the items in the form collection
tmp=tmp & vbcrlf & vbcrlf & "Form Object" & vbcrlf
For Each item In Request.form
tmp=tmp & item & "=" & Request.form(item) & vbcrlf
Next
end if
if session.Contents.count>0 then
'Get all the items in the session object
tmp=tmp & vbcrlf & vbcrlf & "Session Object" & vbcrlf
For Each sessitem in Session.Contents
tmp=tmp & sessitem & ":" & Session.Contents(sessitem)
tmp=tmp & vbcrlf
Next
end if
'Get all the server variables
tmp=tmp & vbcrlf & vbcrlf & "Server Variables" & vbcrlf
For Each name In Request.ServerVariables
tmp=Tmp & trim(name) & ": " & Request.ServerVariables(name)
tmp=tmp & vbcrlf
next
'Spam stopper
'The application object is used to make sure that
'we only report this error once per page error occurence.
'This will prevent one page with error from filling your mailbox.
'But of course this won't stop several pages with errors from
'filling your mailbox.
if Application("LastError")<>(strPage & strLine) then
'Send an email to the WEBMASTER of your site
'You have to include your own sendmail routine here!
SendErrorEmail(tmp)
'You could also log this error to a textfile instead
'of emailing it.
'Store the current page and line in the application object
Application("LastError")= strPage & strLine
end if
'Debug code, remove comments below if you want to display the error
'in the browser instead
'tmp=Replace(Tmp,chr(13) & chr(10),"<br>" & chr(13) & chr(10))
'response.write tmp
'response.flush
%>
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
