【问题标题】:Can't make httpErrors to work无法使 httpErrors 工作
【发布时间】:2016-07-28 22:05:13
【问题描述】:

我已将以下内容添加到配置文件中。

<system.webServer>
  ...
  <httpErrors errorMode="Custom"
              existingResponse="Replace" 
              defaultResponseMode="ExecuteURL">
    <clear/>
    <error statusCode="404"
           responseMode="ExecuteURL"
           path="http://google.se" />
  </httpErrors>
</system.webServer>

但是,我似乎仍然得到带有黄色背景和堆栈跟踪的默认页面。我尝试在 system.web 中注释掉错误处理过滤器和添加/删除自定义错误。 (我正在尝试this great article 中建议的httpErrors 方法。)

我错过了什么?我还能做些什么来解决它?

【问题讨论】:

    标签: c# asp.net-mvc error-handling web-config http-error


    【解决方案1】:

    您可以像这样在 ASP.NET 级别执行此操作:

    <system.web>
        ...
        <customErrors mode="On">
            <error statusCode="404" redirect="http://www.google.se"/>
        </customErrors>
    </system.web>
    

    如果你真的想在 IIS 级别加点它,你可以这样:

    <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404"/>
            <error statusCode="404" path="http://www.google.fr" responseMode="Redirect"/>
        </httpErrors>
    </system.webServer>
    

    当您要重定向到绝对 URL 时,必须将“responseMode”属性设置为“Redirect”,“ExecuteURL”用于动态提供的内容,来自MSDN

    【讨论】:

    • 不确定是不是这样——那是很久以前的事了。但是,知道固执的我,如果它没有帮助,我会要求跟进,所以我认为它确实有帮助,我马虎或压力大,因此错过了你的提醒。对此表示歉意。你应该更用力地戳我。给出答案仅出于两个原因 - 被接受或跟进。对不起。还有 you.Future = new Anno{ happy = true } 让你微笑。
    猜你喜欢
    • 1970-01-01
    • 2014-04-10
    • 2014-04-03
    • 2011-07-14
    • 2013-12-25
    • 2011-10-29
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多