【问题标题】:Errors not being redirected to an Http handler if redirectMode="ResponseRewrite"如果 redirectMode="ResponseRewrite" 则错误未重定向到 Http 处理程序
【发布时间】:2011-02-11 02:46:14
【问题描述】:

我看到类似的问题,但似乎是由于不相关的问题。

在 3.5 中,我有一个自定义错误处理程序,用于记录错误并重定向用户。我的 web.config 是这样设置的:

    <httpHandlers>
                 <add path="error.ashx" type="MySite.Tools.WebErrorLogger, MySite.Tools" verb="*"/>
    </httpHandlers>
    <customErrors mode="On" defaultRedirect="error.ashx"
                  redirectMode="ResponseRewrite">
    </customErrors>

当 redirectMode 设置为 "ResponseRedirect" 时,一切正常(但 Server.GetLastError() 为空,但这似乎是有意的)

但是,当使用ResponseRewrite 时,我的处理程序没有被调用,并且我看到了 ASP.Net 默认错误页面。知道我该怎么做吗?

(很遗憾,由于其他限制,我无法使用 aspx 页面或在 global.asax 中进行错误处理)

【问题讨论】:

    标签: .net asp.net error-handling httphandler


    【解决方案1】:

    好吧,我过去曾问过pretty similar question

    解决方案是将错误页面转换为静态 HTML 页面。
    动态页面肯定有什么错误,但是我没找到。

    【讨论】:

    • Web 表单和路由也有同样的问题,在我的情况下,即使静态页面也不起作用,所以我删除了 redirectMode="ResponseRewrite"
    【解决方案2】:

    我遇到了同样的问题,我发现原因显然是 .ashx 文件,如果您使用普通的 .aspx 它会起作用,它对我有用;我仍在尝试了解如何使用 REsponseRewrite “启用” .ashx 文件扩展名,因为在我的情况下,它比使用 aspx 页面更合乎逻辑。我在这里有一个关于这个主题的开放线程:

    http://social.msdn.microsoft.com/Forums/it-IT/aspnetit/thread/7b8f5e36-44a8-40ea-bd73-2e99a1fd42dd

    【讨论】:

      【解决方案3】:

      在当前的 .NET(从 4.5 开始)中,无法使用 ashx 处理程序来做到这一点。

      ResponseRewrite 使用 HttpServerUtility.Execute,它被硬编码为只允许 aspx 页面或静态文件(或旧版 ASP 页面)。

      【讨论】:

        猜你喜欢
        • 2013-06-07
        • 1970-01-01
        • 2010-12-08
        • 2010-10-21
        • 2010-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多