4

我正在开发一个在 IIS 8.5 上运行的(Web 窗体)站点,目前正在为 404 和 500 设置错误处理。

我已经有了system.web>customErrors设置,但是由于我们在集成模式/更新版本的 IIS 下运行,它是从system.webServer>中提取的httpErrors

使用 IIS GUI,我选择在站点上用静态 HTML 文件替换标准 IIS 错误页面:

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

不幸的是,虽然显示了正确的错误页面,但不是返回 404,而是返回 200,对于 500 错误,返回 302 后跟 200。

对于旧版本的 IIS,或未在集成模式下运行的 IIS,您可以redirectMode="ResponseRewrite"customErrors元素上进行设置,这将解决此问题。

我已尝试设置所有三个existingResponse可用httpErrors选项,并尝试更新设置responseMode="File",但这些都没有改变。

httpErrrors有没有办法为元素做类似的事情?还是我坚持将错误指向 ASP.NET 页面并从那里返回适当的错误?

谢谢!

4

1 回答 1

5

为了解决这个问题,您可以将此配置设置到<httpErrors>您的 WebConfig 文件中。像这样:

<system.webServer>
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <clear/>
      <error statusCode="404" path="/WebForms/Index.aspx" responseMode="File"/>
    </httpErrors>
<system.webServer/>

responseMode=File保留原始错误代码,并显示静态页面。

于 2015-12-29T00:08:24.170 回答