vb Error handler

<%@ Language=VBScript %>
<%
	Option Explicit

	Dim ASPErr
	Dim strError
	Dim sv 'server variable
	Dim EmailError

	Set ASPErr = Server.GetLastError
	Response.Clear
	
	strError = ""

	If Err.number = 0 Then
		strError = strError & "------------------------------------------------------" & vbCrLf
		strError = strError & "Error Time: " & Now & vbCrLf
		strError = strError & "Session ID: " & Session.SessionID & vbCrLf
		strError = strError & "HTTP_X_ORIGINAL_URL: " & Request.ServerVariables("HTTP_X_ORIGINAL_URL") & vbCrLf
		strError = strError & "URL: " & Request.ServerVariables("URL") & vbCrLf
		strError = strError & "---------------------------------------------ASP Error" & vbCrLf
		If ASPErr.ASPCode <> "" Then strError = strError & "* Error #: " & ASPErr.ASPCode & vbCrLf
		If ASPErr.Number <> 0 Then strError = strError & "* COM Error #: " & ASPErr.Number & " (" & Hex (ASPErr.Number) & ")" & vbCrLf
		If ASPErr.Source <> "" Then strError = strError & "* Source: " & ASPErr.Source & vbCrLf
		If ASPErr.Category <> "" Then strError = strError & "* Category: " & ASPErr.Category & vbCrLf
		If ASPErr.File <> "" Then strError = strError & "* File: " & "/" & Request.ServerVariables ("SERVER_NAME") & ASPErr.File & vbCrLf
		If ASPErr.Line <> 0 Then strError = strError & "* Line, Column:" & ASPErr.Line & ", " & ASPErr.Column & vbCrLf
		If ASPErr.Description <> "" Then strError = strError & "* Description: " & ASPErr.Description & vbCrLf
		If ASPErr.ASPDescription <> "" Then strError = strError & "* ASP Desc: " & ASPErr.ASPDescription & vbCrLf
		strError = strError & "------------------------------------------HTTP Headers" & vbCrLf
		strError = strError & Replace(Request.ServerVariables("ALL_HTTP"),vbLf,vbCrLf)
		strError = strError & "--------------------------------------Server Variables" & vbCrLf
		For Each sv In Request.ServerVariables()
			strError = strError & UCASE(sv) & ":" & Request.ServerVariables(sv) & vbCrLf
		Next
		strError = strError & "-----------------------------------------------Session" & vbCrLf
		For Each sv In Session.Contents()
			strError = strError & UCASE(sv) & ":" & Session.Contents(sv) & vbCrLf
		Next
		strError = strError & "------------------------------------------------------" & vbCrLf
	End If
%>
Use for getting the last error and generating a report for logging to file/emailing - as used on slickcms. This will require setting up a 500.100 Custom error in IIS to redirect to the URL of the asp page.

Updated: Saturday 9th October 2010, 05:36pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.