【发布时间】:2015-02-15 05:56:55
【问题描述】:
在我的 web.config 中,您可以看到 redirectMode="ResponseRewrite"。我读到这是我需要保留状态代码的内容。不幸的是,一旦我把它放进去,我就会得到:
“处理您的请求时发生异常。此外,在执行第一个异常的自定义错误页面时发生另一个异常。请求已终止。”
省略此变量成功将我重定向到 ~/Error/Index.cshtml,但响应为 200.doh。任何方向都将不胜感激,谢谢。
<system.web>
<compilation debug="true" targetFramework="4.5" />
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/Index"/>
<error statusCode="500" redirect="~/Error/Index"/>
</customErrors>
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL">
<remove statusCode="403"/>
<remove statusCode="404"/>
<remove statusCode="500"/>
<error statusCode="403" path="~/Error/Index" responseMode="File"/>
<error statusCode="404" path="~/Error/Index" responseMode="File"/>
<error statusCode="500" path="~/Error/Index" responseMode="File"/>
</httpErrors>
</system.webServer>
在我的 filterconfig.cs 中:
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// does this conflict?
filters.Add(new HandleErrorAttribute());
}
}
【问题讨论】:
标签: c# asp.net-mvc-5