Error pages not found, throwing ELMAH error with Custom Error Pages

徘徊边缘 提交于 2019-11-30 05:08:33

Finally got it working to my satisfaction...

The Elmah.Mvc package applies a "hidden" error handler. I've disabled this by adding the following line in web.config <appSettings> (the value was set to "false" by default from nuget install)

<add key="elmah.mvc.disableHandleErrorFilter" value="true" />

So, now my errors propagate up to Application_Error and are logged by Elmah, bypassing the Elmah filter, and display the proper error page (not the one in /shared/error.cshtml)

If you are running in IIS 7 integrated mode, you will need to add Response.TrySkipIisCustomErrors = true; in Application_Error. Otherwise IIS will still redirect the client to a custom error page, despite anything you do in code.

See here for additional details: http://www.west-wind.com/weblog/posts/2009/Apr/29/IIS-7-Error-Pages-taking-over-500-Errors

Edit: here's the body of my Application_Error:

if (HttpContext.Current != null)
{
    Server.ClearError();
    Response.TrySkipIisCustomErrors = true;
    RouteData data = new RouteData();
    data.Values.Add("controller", "Error");
    data.Values.Add("action", "Error");
    IController controller = new MyApp.Controllers.ErrorController();
    controller.Execute(new RequestContext(new HttpContextWrapper(Context), data));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!