Click here to Skip to main content
15,884,064 members
Articles / Desktop Programming / MFC
Article

Trap ASP and SQL errors in your site

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
25 Apr 2002 63.3K   33   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

VBScript
<%
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


Written By
Web Developer
Argentina Argentina
Lic. Fernando Finelli

Comments and Discussions

 
QuestionHow it go to error section in asp error trap Pin
anil12398@yahoo.co.in15-Jan-07 18:16
anil12398@yahoo.co.in15-Jan-07 18:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.