无法使 httpErrors 工作

Can't make httpErrors to work

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

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

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

我错过了什么?我还能做些什么来排除故障?

你可以像这样在 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.