ASP.NET MVC 5 error handling

前端 未结 3 1454
深忆病人
深忆病人 2020-11-28 07:36

We want to handle 403 errors, 404 errors, all errors due to a MySpecialDomainException and provide a default error page for all other errors (including errors i

3条回答
  •  情话喂你
    2020-11-28 08:03

    Better way of handling error is extending handleerror attribute. Handle error attribute has following advantages

    • With HandleErrorAttribute we get more control over exception handling. HandleError allow us to handle error differently for different controllers and actions easily where in Application_Error to get this feature we take the help of switch loop.

    • Once you are into Application_Error you are out of MVC and you will lose ControllerContext and then we cannot do much things which will easily possible with HandleError.

    see the following post for how to extend error handling attribute and advantages

    Advantages of [HandleError] over Application_Error

    http://maheshde.blogspot.com.au/2012/09/error-handing-with-mvc-using-custom.html

    http://www.codeproject.com/Articles/731913/Exception-Handling-in-MVC

提交回复
热议问题