Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Trap ASP and SQL errors in your site

0.00/5 (No votes)
25 Apr 2002 1  
Trap the ASP and SQL errors in your Site

Introduction

This article shows you how to trap the ASP & SQL errors in your site.

First thing to do is to change the Custom Error for The Web Site Properties
[Internal Server Error] - HTTP Error 500 & 500;5001 to this URL -> /trap.asp 

Now create the trap.asp file using the code shown below.

Code Listing

<%
Const lngMaxFormBytes = 200

Response.Buffer = true

If Response.Buffer Then
    Response.Clear
    Response.Status = "500 Internal Server Error"
    Response.ContentType = "text/html"
    Response.Expires = 0
End If

Set objASPError = Server.GetLastError

strServername     = LCase(Request.ServerVariables("SERVER_NAME"))
strServerIP     = Request.ServerVariables("LOCAL_ADDR")
strRemoteIP     = Request.ServerVariables("REMOTE_ADDR")
strCategory     = objASPError.Category
strASPCode     = Server.htmlEncode(objASPError.ASPCode)
intNumber     = objASPError.Number
strFile         = objASPError.File
intLine         = objASPError.Line
intColumn     = objASPError.Column
strSource     = server.htmlEncode(objASPError.Source)
strDescription     = Replace(Server.htmlEncode( _
    objASPError.Description),"'","-")
strASPDescription= Replace(Server.htmlEncode( _
    objASPError.ASPDescription),"'","-")

Response.Write "Sorry, but the site is not available."
%>

You could send the email to the webmaster, with the error.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here