如果打开自定义错误,是否会触发global.asax Application_Error事件?

如果在Web配置中将自定义错误设置为RemoteOnly – 这是否意味着global.asax中的MVC应用程序级别错误事件 – Application_Error不会因错误而触发?

我刚刚注意到,当我的应用程序中发生某个错误,并且我正在远程查看该站点时,不会记录任何错误。 但是,当我访问服务器上的应用程序并发生相同的错误时,将记录错误。

这是自定义错误配置设置:

      

编辑

只是出于对人们的兴趣 – 我最终完全关闭了自定义错误并在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); } } 

如果不调用Server.ClearError或在Page_Error或Application_Error事件处理程序中捕获错误,则会根据Web.config文件部分中的设置处理错误。

有关更多信息,请参阅此SO问题