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?
Try removing the following line from your Global.asax:
The
HandleErrorattribute intercepts all exceptions in Release mode and attempts to render theError.cshtmlview. You probably have deleted this view from the~/Views/Sharedfolder and so when an unhandled exception is thrown this exception handler intercepts the exception and attempts to render an non-existent view.