我正在开发一个在 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 页面并从那里返回适当的错误?
谢谢!