I have my ASP.NET MVC 3 application configured to redirect to an Errors
controller with two actions -
<customErrors mode="On" defaultRedirect="/Errors/ApplicationError">
<error statusCode="404" redirect="/Errors/NotFound" />
</customErrors>
I have a couple of views that are rendered from each of the action methods:
/Views/Shared/NotFound.cshtml
/Views/Shared/ApplicationError.cshtml
In my ErrorsController
ApplicationError
action I do the following:
public ActionResult ApplicationError()
{
Response.StatusCode = 500;
return View();
}
This works and my ApplicationError.cshtml
view is rendered, whatever exception happened is logged, all good.
However in ELMAH I see this extra error being logged:
System.InvalidOperationException The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Throw/Error.aspx ~/Views/Throw/Error.ascx ~/Views/Shared/Error.aspx ~/Views/Shared/Error.ascx ~/Views/Throw/Error.cshtml ~/Views/Throw/Error.vbhtml ~/Views/Shared/Error.cshtml ~/Views/Shared/Error.vbhtml
Why is ASP.NET MVC still hunting for these views when I've already handled the error and my own view is successfully located and rendered?
Additional Information:
I don't use the
[HandleError]
attribute anywhereI replaced
filters.Add(new HandleErrorAttribute());
inGlobal.asax.cs
withfilters.Add(new ElmahHandleErrorAttribute());
as per this advice which is based on this Stack Overflow answer by Atif the author of ELMAH.
HandleErrorAttribute
isn't applied globally. Look inRegisterGlobalFilters
inglobal.asax.cs
. – JimmiThThrowsController
- i.e., is that the real name of yourErrorController
or is it the controller that originally threw the exception? – JimmiTh