【发布时间】:2014-10-05 01:37:59
【问题描述】:
设置:
- HandleErrorAttribute 已被移除并清除所有过滤器。
- Global.asax 中未捕获或处理异常
IIS 错误的 web.config 设置如下:
<httpErrors errorMode="Custom" existingResponse="Replace" defaultPath="/StaticErrors/Default.html" defaultResponseMode="ExecuteURL">
<clear />
<error statusCode="400" path="/myCustomErrors/Http400" responseMode="ExecuteURL" />
<error statusCode="401" path="/myCustomErrors/Http401" responseMode="ExecuteURL" />
<error statusCode="403" path="/myCustomErrors/Http403" responseMode="ExecuteURL" />
<error statusCode="404" path="/myCustomErrors/Http404" responseMode="ExecuteURL" />
<error statusCode="500" path="/myCustomErrors/Http500" responseMode="ExecuteURL" />
</httpErrors>
这正常工作,但是,如果我添加以下 customErrors 代码 - 那么任何错误,例如错误请求或未找到将总是导致错误 500 页面显示。由于某种原因,HttpException 被视为未处理的异常。
<customErrors defaultRedirect="/StaticErrors/Default.html" mode="On" redirectMode="ResponseRewrite">
<error redirect="~/myCustomErrors/Http400" statusCode="400" />
<error redirect="~/myCustomErrors/Http401" statusCode="401" />
<error redirect="~/myCustomErrors/Http403" statusCode="403" />
<error redirect="~/myCustomErrors/Http404" statusCode="404" />
<error redirect="~/myCustomErrors/Http500" statusCode="500" />
</customErrors>
在仅 MVC 的应用程序中以这种方式禁用 ASP.NET 错误处理会影响哪些问题。
【问题讨论】:
-
尝试删除
~ -
有或没有 ~ 没有任何区别。我认为加载基于 MVC 的异常页面可能存在进一步的错误。但是失败的请求跟踪什么也没显示。直接导航到 MVC 错误页面也可以正常工作。包含 customErrors 时,始终执行“/myCustomErrors/Http500”。
-
在您的自定义错误中尝试
500.100状态代码而不是500。
标签: asp.net asp.net-mvc exception-handling