Link to home
Start Free TrialLog in
Avatar of benners70
benners70

asked on

ASP - Send custom errors to error 500 page

When an error occurs in my ASP page scripts the visitor gets set to a customised error 500 page which displays the standard errors properties from Server.GetLastError()

I would like to be able to send through other useful debugging information such as
Request.servervariables("ALL_HTTP") and perhaps a SQL string if available.

The code below is my attempt to pass custom variables to my custom 500.asp page. It redirects ok but it not working right as it nolonger displays the error properties of Server.GetLastError()

Any ideas on how to achieve this?

Thank you. Paul.
<%@Language="VBSCRIPT"%>
<% On Error Resume Next %>
<html>
<head>
<title>Bad Page 1</title>
</head>
<body>
<% Response.Write 1/0 %>
</body>
</html>
<%
If Err.number <> 0 then
 	Response.Clear
	errorString = Request.servervariables("ALL_HTTP")
	response.Redirect("500.asp?customerrors=" & errorString)
End If
%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Wayne Barron
Wayne Barron
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of benners70
benners70

ASKER

Hi Carrzkiss, thanks for your reply.

I wasn't immediately sure what you have provided but I replaced my custom error 500 page with your code and it worked, but I'm not sure it's quite what I was after.

I think key question I have is can I pass variables used on the page with an error through to the IIS error page for display and still get access to all the properties of Server.GetLastError()?

I can of course redirect to another error handling page if  an error is found and pass variables that exist on the page that had the error (see code snippet). But if I do this, I don't seem to be able to access to the properties of Server.GetLastError() unless I go through to the IIS error 500 page.

If Err.number <> 0 then
	if variableName1 <> "" then 
		errorVariables = variableName1 
	end if
	if variableName2 <> "" then 
		errorVariables = errorVariables & variableName2 
	end if
	response.Redirect("anotherPage.asp?errorVariables=" & errorVariables)
        'OR
        'fnSendErrorVariables errorVariables 
        'response.Redirect("myCustomError500IISpage.asp")
end if

Open in new window

Try this.
http://www.devguru.com/technologies/ASP/quickref/server_getlasterror.html
<%
Dim objErrorInfo
Set objErrorInfo = Server.GetLastError 
 
Response.Write("ASPCode = " & objErrorInfo.ASPCode)
Response.Write("ASPDescription = " & objErrorInfo.ASPDescription)
Response.Write("Category = " & objErrorInfo.Category)
Response.Write("Column = " & objErrorInfo.Column)
Response.Write("Description = " & objErrorInfo.Description)
Response.Write("File = " & objErrorInfo.File)
Response.Write("Line = " & objErrorInfo.Line)
Response.Write("Number = " & objErrorInfo.Number)
Response.Write("Source = " & objErrorInfo.Source)
%> 

Open in new window

Hi Carrzkiss

From the info you've given, it seems it's not possible to either:
a) pass variables from a page with an error through to a custom IIS error500 page
b) access Server.GetLastError anywhere other that in the IIS error500  page

In laymans terms for the ISS error500 page to load the page with an error can't load and for a page with an error to resume next and load would mean the  ISS error500 page cannot be accessed.

If I'm incorrect in these conclusions I'd be pleased to here.

However, by accessing various ServerVariables in my custom error 500 page I am able to debug most errors.

Thanks
to bad we could not do what you really wanted.
So, the [B] is ok, considering that it was not what you was really needing.

Have a good one.
Carrzkiss