.NET MVC Server_GetLastError始终返回缺少的视图错误

nth*_*xel 3 error-handling asp.net-mvc-3

我正在尝试在MVC 3中实现全局未处理的异常日志记录.我已经设置了我的web.config,就像这样..

<customErrors mode="On" defaultRedirect="/error/">
  <error statusCode="500" redirect="/error/http500"/>
  <error statusCode="404" redirect="/error/http404"/>
</customErrors>
Run Code Online (Sandbox Code Playgroud)

当我触发控制器的异常时,它会按预期重定向到错误页面.问题是,当我Server.GetLastError()在Global.asax中使用时,异常总是如此

"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"
Run Code Online (Sandbox Code Playgroud)

我期待它提供抛出的实际异常.我究竟做错了什么?

Dar*_*rov 5

尝试从Global.asax中删除以下行:

filters.Add(new HandleErrorAttribute());
Run Code Online (Sandbox Code Playgroud)

HandleError属性拦截发布模式中的所有异常并尝试呈现Error.cshtml视图.您可能已从该~/Views/Shared文件夹中删除了此视图,因此当抛出未处理的异常时,此异常处理程序会拦截该异常并尝试呈现不存在的视图.