I\'ve made some modifications to Global.asax so that I can show custom error pages (403, 404, and 500) Here\'s the code:
public class MvcApplication : Sy
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));
}
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)