Reputation: 3109
I'm trying to implement global unhandled exception logging in MVC 3. I've set up my web.config like so..
<customErrors mode="On" defaultRedirect="/error/">
<error statusCode="500" redirect="/error/http500"/>
<error statusCode="404" redirect="/error/http404"/>
</customErrors>
When I trigger an exception for the controller, it redirects to the error page as expected. The problem is, when I use Server.GetLastError()
in Global.asax, the exception is always
"The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:\r\n~/Views/deanslist/Error.aspx\r\n~/Views/deanslist/Error.ascx\r\n~/Views/Shared/Error.aspx\r\n~/Views/Shared/Error.ascx\r\n~/Views/deanslist/Error.cshtml\r\n~/Views/deanslist/Error.vbhtml\r\n~/Views/Shared/Error.cshtml\r\n~/Views/Shared/Error.vbhtml"
I was expecting it to provide the actual exception that was thrown. What am I doing wrong?
Upvotes: 3
Views: 668
Reputation: 1038720
Try removing the following line from your Global.asax:
filters.Add(new HandleErrorAttribute());
The HandleError
attribute intercepts all exceptions in Release mode and attempts to render the Error.cshtml
view. You probably have deleted this view from the ~/Views/Shared
folder and so when an unhandled exception is thrown this exception handler intercepts the exception and attempts to render an non-existent view.
Upvotes: 5