Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASPError object doesn't contain any data on my custom error page

I have the following in my web.config

<httpErrors errorMode="Custom">
    <remove statusCode="500" subStatusCode="-1" />
    <error statusCode="500" prefixLanguageFilePath="" path="/error.asp" responseMode="ExecuteURL" />
</httpErrors>

The error handling is working in that, when a 500 error occurs, I am sent to my error.asp instead of the default 500 error page.

The issue is that none of the properties of the ASPError object returned by Server.GetLastError are set.

For example, in the code below, the error description is

dim oErr : set oErr = Server.GetLastError

Response.Write "Error Description:  " & oErr.Description& "<br />"

Update

Based on the thread Joel linked to in the comments, I've updated my web.config to the following:

<httpErrors errorMode="Custom">
    <remove statusCode="500" subStatusCode="100" />
    <error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/error.asp" responseMode="ExecuteURL" />
</httpErrors>

This does give me data in the ASPError object returned by GetLastError.

The issue now is that I'm getting the HTML from the beginning of the page where the error is generated, then the rest of the page is the HTML from error.asp.

I'd really like it to redirect to error.asp instead but changing the web.config to responseMode="Redirect" doesn't seem to work.

like image 218
Mark Biek Avatar asked Nov 09 '10 16:11

Mark Biek


1 Answers

Here's the solution that's working for me.

Setup up the web.config like this:

<httpErrors errorMode="Custom">
    <remove statusCode="500" subStatusCode="100" />
    <error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/error.asp" responseMode="ExecuteURL" />
</httpErrors>

A simple error.asp might look like this:

<%@ Language=VBScript %>
<% 
    Option Explicit
    On Error Resume Next
    Response.Clear
    Dim objError, MessageBody
    Set objError = Server.GetLastError()

    Response.Write objError.ASPCode & "<br />"
    Response.Write objError.Number & "<br />"
    Response.Write objError.Description & "<br />"
%>

The key to my problems appears to be having On Error Resume Next and Response.Clear.

I found the solution on the Creating Custom ASP Error Pages Microsoft KB article (Q224070).

like image 196
Mark Biek Avatar answered Sep 28 '22 03:09

Mark Biek