I have custom error handling defined for my application and it all works wonderfully - when a resource cannot be found, the correct 'NotFound' view renders. When an unhanlded exception occurs, the 'ServerError' view renders.
The problem I am facing is that my application insists on trying to find a View called 'Error' but doesn't find it, as i don't have one and thus this exception gets thrown during my custom error handling routine:
"The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ... "
I have an Application_Error event handler which does the logging of all unhandled exceptions:
protected void Application_Error(Object sender, EventArgs e)
{
Exception lastEx = Server.GetLastError();
// Attempt to Log the error
try
{
Utils.Logger.Error(lastEx);
}
catch (Exception loggingEx)
{
// Try and write the original ex to the Trace
Utils.TryTrace(lastEx.Message);
// Try and write the logging exception to the Trace
Utils.TryTrace(loggingEx.Message);
}
}
I have customErrors turned 'On' in my web.config:
<customErrors mode="On" defaultRedirect="blah">
<error statusCode="404" redirect="dee"/>
<error statusCode="500" redirect="blah"/>
</customErrors>
And i have routes defined in my Global.asax.cs RegisterRoutes method which correspond to the Redirect defined in web.config above:
routes.MapRoute(
"Error - 404",
"dee",
new { controller = "Error", action = "NotFound" }
);
routes.MapRoute(
"ServerError", // When this route is matched we want minimal error info displayed
"blah",
new { controller = "Error", action = "ServerError" }
);
I have a BaseController which contains an OnActionExecuted routine:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
Logger.Info(String.Format(Constants.LOG_ACTION_EXECUTED, filterContext.Controller.ToString(), filterContext.ActionDescriptor.ActionName));
// Log any exceptions
if (filterContext.Exception != null)
{
Stack<string> messages = new Stack<string>();
Exception current = filterContext.Exception;
messages.Push(current.Message);
while (current.InnerException != null)
{
messages.Push(current.InnerException.Message);
current = current.InnerException;
}
StringBuilder result = new StringBuilder();
while (messages.Count != 0)
{
result.Append(messages.Pop());
string nextline = messages.Count > 0 ? "OUTER EXCEPTION " + messages.Count + ": " : "";
result.Append(Environment.NewLine);
}
Logger.Error(result.ToString());
}
base.OnActionExecuted(filterContext);
}
Is there somewhere else that the Framework defines which view to render in the event of an unhandled exception?
Is my custom error handling routine missing a final step which would ensure that the Framework no longer expects to find the 'Error' view???