jcv*_*dan 13 .net c# asp.net-mvc
如果您RemoteOnly在Web配置中设置了自定义错误- 这是否意味着MVC的应用程序级错误事件global.asax- Application_Error错误时不会触发?
我刚刚注意到,当我的应用程序发生某个错误,并且我正在远程查看该站点时,不会记录任何错误.但是,当我访问服务器上的应用程序并发生相同的错误时,将记录错误.
这是自定义错误配置设置:
<customErrors defaultRedirect="/Error/Application" mode="RemoteOnly">
<error statusCode="403" redirect="/error/forbidden"/>
<error statusCode="404" redirect="/error/notfound"/>
<error statusCode="500" redirect="/error/application"/>
</customErrors>
Run Code Online (Sandbox Code Playgroud)
编辑
只是出于对人们的兴趣 - 我最终完全关闭了自定义错误并处理重定向Application_Error:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
// ... log error here
var httpEx = exception as HttpException;
if (httpEx != null && httpEx.GetHttpCode() == 403)
{
Response.Redirect("/youraccount/error/forbidden", true);
}
else if (httpEx != null && httpEx.GetHttpCode() == 404)
{
Response.Redirect("/youraccount/error/notfound", true);
}
else
{
Response.Redirect("/youraccount/error/application", true);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21271 次 |
| 最近记录: |