1

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?

Artyom Neustroev
  • 8,627
  • 5
  • 33
  • 57
  • As error explain your site failed to report failure. To debug start with breaking on exceptions in your code (Debug->Exception->CLR=throw), if it is not enough - turn off Tool->Options->Debug->"My Code Only" to catch all exceptions. – Alexei Levenkov Oct 23 '13 at 05:29
  • Might be of use : http://stackoverflow.com/questions/3541426/how-to-get-asp-net-mvc-to-match-dot-character-at-the-end-in-a-route – Jason Evans Oct 23 '13 at 08:01
  • @AlexeiLevenkov it says "Failed to map the path" at `System.Web` – Artyom Neustroev Oct 23 '13 at 08:02
  • http://stackoverflow.com/questions/294495/semantic-urls-with-dots-in-net – Girish Sakhare Oct 23 '13 at 11:41
  • @GirishSakhare link should provide you the solution to immediate problem, but you also look into why your error page failed with exception... – Alexei Levenkov Oct 23 '13 at 16:23
  • @GirishSakhare @JasonEvans thank you, that helps to get rid of the exception. But why it is not handled in `Applicaiton_Error` initially? – Artyom Neustroev Oct 23 '13 at 16:29

0 Answers0