开发者

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" prefixLanguage开发者_运维百科FilePath="" 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.


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).


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.

Place a

Response.Clear

in your custom error page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜