I used to have a custom error page in ASP on IIS 4.
When we upgraded to IIS 5 it stopped working.
I'm puzzled as to why it's not working and I've searched hi and low for a solution. I consider this difficult because I have not been able to locate the answer and the page works when called directly.
1) Desired Result: Upon an error, this page is called and an email is sent detailing the problem. The user sees a friendly error page. Critical details are hidden from prying eyes.
What's happening:
- When an error occurs, the page loads, but doesn't send the email or display the error.
- When the page is called directly
www.server.com\errors\404.asp It works and sends the email.
- when the page is called by IIS in response to an error, nothing. No error, no string, no email.
Language used, VB Script.
Used to be CDONTS, upgraded to new CDO model (really easy actually).
What I've tried:
I've hardcoded some response.write strings to force the output and try to trace the issue.
Server Environment:
Capable hardware, running 2003 Web Server Edition.
Stable production web server
Acceptable to good security configuration.
We have the machine audited weekly.
We are running the lockdown script to disable ports.
Server is on a firewalled network. So when we look at the server directly the 192.168.1.x test will spit out the error directly so we can see it.
Other observations:
The page works when called directly.
Emails work from other functions on the site.
Removing all code except the email generator results in the same activity, no email is sent.
Hunches:
1) Server configuration that I don't know about.
2) Restriction in execution capabilities during error... ?
3) Minor mistake in code somewhere.
Live example ommitted because when I get it working I don't want 33000 emails.
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX">
<title>A system Error has occured.</title>
</head>
<body >
<%
Dim objASPError, blnErrorWritten, strServername, strServerIP, strRemoteIP
'If Response.Buffer Then
' Response.Clear
' Response.Status = "Server Error"
' Response.ContentType = "text/html"
' Response.Expires = 0
'End If
Set objASPError = Server.GetLastError
Dim strErrorDescription
strErrorDescription = "Category=" & objASPError.Category & vbCrLf
If objASPError.ASPCode <> "" Then
strErrorDescription = strErrorDescription & "Code=" & objASPError.ASPCode & vbCrLf
End If
strErrorDescription = strErrorDescription & "Number=(0x" & Hex(objASPError.Number) & ")" & vbCrLf
strErrorDescription = strErrorDescription & "Description=" & objASPError.Description & vbCrLf
If objASPError.ASPDescription
<> "" Then
strErrorDescription = strErrorDescription & "ASP Error Description=" & objASPError.Description
End If
blnErrorWritten = False
strServername = LCase(Request.ServerVariab
les("SERVE
R_NAME"))
strServerIP = Request.ServerVariables("L
OCAL_ADDR"
)
strRemoteIP = Request.ServerVariables("R
EMOTE_ADDR
")
If objASPError.Source <> "" Then
strErrorDescription = strErrorDescription & "File=" & objASPError.File & vbCrLf
If objASPError.Line > 0 Then
strErrorDescription = strErrorDescription & "Line=" & objASPError.Line
End If
If objASPError.Column > 0 Then
strErrorDescription = strErrorDescription & ", Column= " & objASPError.Column
End If
strErrorDescription = strErrorDescription & vbCrLf
strErrorDescription = strErrorDescription & "Code:" & vbCrLf & Server.HTMLEncode(objASPEr
ror.Source
) & vbCrLf
If objASPError.Column > 0 Then
strErrorDescription = strErrorDescription & String((objASPError.Column
- 1), "-") & "^" & vbCrLf
End If
blnErrorWritten = True
End If
If Not blnErrorWritten And objASPError.File <> "?" Then
strErrorDescription = strErrorDescription & vbCrLf & "Filename=" & objASPError.File & vbCrLf
If objASPError.Line > 0 Then
strErrorDescription = strErrorDescription & "Number=" & objASPError.line
End If
If objASPError.Column > 0 Then
strErrorDescription = strErrorDescription & ", Column=" & objASPError.Column
End If
strErrorDescription = strErrorDescription & vbCrLf
End If
Dim mymail, strBody
Set mymail = Server.CreateObject("CDO.m
essage")
mymail.From = "ommitted"
mymail.To ="ommitted"
mymail.Subject = "ASP Error Occurred @"&now&" on "&date
strBody = "An error occured on server=" & strServername&vbcrlf&" IP Address=" & strServerIP&vbcrlf
strbody = strbody &vbcrlf& " Client IP=" & strRemoteIP&vbcrlf
strBody = strBody & " at " & Now() & vbCrlf
strBody = strBody & "BrowserType=" & Request.ServerVariables("H
TTP_USER_A
GENT") & vbCrlf
strbody = strbody & "Method=" & Request.ServerVariables("R
EQUEST_MET
HOD") & vbCrlf
strbody = strbody&"URL Called was: "&request.servervariables(
"URL")&vbc
rlf
strbody = strbody&"Query was: "&request.servervariables(
"query_str
ing")&vbcr
lf
strbody = strbody&"Path was: "&request.servervariables(
"Path_tran
slated")&v
bcrlf
strbody = strbody&"Referred by: "&request.ServerVariables(
"HTTP_REFE
RER")&vbcr
lf
strbody = strbody& "Error Message:"&vbcr&strErrorDes
cription & vbCrLf
if sqlstring<>"" then strbody = strbody& "SQL"&sqlstring
mymail.textBody = strBody
response.write(strbody)
mymail.Send
Set mymail = Nothing
if instr(1,strremotip,"192.16
8.1",1)>0 then response.write(strbody)
Start Free Trial