I am trying to install a nice global exception handling mechanism that centrally manages generic thrown exceptions, as well as 404, 500, ... errors; that is, without having to implement different error pages / error handling solutions for different errors.
To that effect, I tried to implement this example for calling an ErrorsController from within the Application_Error method of the Global.asax.cs.
However, when I run the code, I run into this exception:
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=The view 'NotFound' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Errors/NotFound.aspx
~/Views/Errors/NotFound.ascx
~/Views/Shared/NotFound.aspx
~/Views/Shared/NotFound.ascx
/favicon.ico
Source=System.Web.Mvc
StackTrace:
at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
at Cider.MvcApplication.Application_Error(Object sender, EventArgs e) in c:\Users\cornelius.kopp\Projects\SD Cider\Cider\Global.asax.cs:line 88
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.HttpApplication.RaiseOnError()
InnerException:
The interesting thing is that I use Razor as view engine and the template definitely exists. I implemented a custom HandleErrorsAttribute
that called the ErrorsController and through that everything worked smoothly. Only when the (basically copy-and-pasted) code was called from the Application_Error method it failed.
Trying to create an NotFound.aspx view in the project yielded the same exception, only that it only lists the favicon.ico as searched location.
Moving the code into the Application_EndRequest, as originally written, yielded the same result
Any explanation to this would be highly appreciated.