ASP.net MVC [HandleError] not catching exceptions

后端 未结 6 983
长发绾君心
长发绾君心 2020-12-08 12:59

In two different application, one a custom the other the sample MVC application you get with a new VS2008 MVC project, [HandleError] is not catching exceptions.

In t

6条回答
  •  无人及你
    2020-12-08 13:45

    I have struggled with this as well and I believe I understand the problem now.

    In short the requirements for having [HandleError] work as expected are:

    You must enable custom errors in web.config AND you must also specify where your error view is in the tag.

    Example:

    
    

    Leaving off the defaultRedirect="Error" part will instead yield a 500 error in the browser--NOT the ASP.NET error page (YSOD).

    Also you do not have to be in Release mode. I tested this with a Debug build and it worked fine.

    My environment was Visual Studio 2010 using .NET 4 and the standard, "ASP.NET MVC 2 Web Application" project template.

    What confused me was the MSDN documentation for the HandleErrorAttribute Class. It doesn't explicitly say you must turn on custom errors in web.config. And I assumed all I needed was the [Handle Error] attribute.

提交回复
热议问题