I am trying to customise the error pages in the MVC4 application using two approaches:
1.I've covered the case for Application_Error
:
RouteData routeData = new RouteData();
routeData.Values.Add("code", errorCode); //this code is from generated exception
routeData.Values.Add("action", "Index");
routeData.Values.Add("controller", "Error");
IController errorController = new ErrorController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
2.Added the "Catch All" route to my route table:
RouteHelper.MapRoute(
"CatchAll",
"{*catchAll}",
defaults: new { controller = "Error", action = "Index", code = "404" }
);
However, I am still encountering a yellow screen of death when I type URL like this (pay attention to the character at the end):
localhost/Home/Index.
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
I thought that any YSOD should trigger Application_Error
, but that
doesn't. What am I missing?