我已将以下内容添加到配置文件中。
<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 方法。)
我错过了什么?我还能做些什么来解决问题?
最佳答案
您可以像这样在 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 .
关于c# - 无法使 httpErrors 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36486099/