Using of HandleErrorAttribute in ASP.NET MVC application

前端 未结 2 553
清歌不尽
清歌不尽 2021-02-14 15:14

I have a question about the best way of using HandleErrorAttribute in my MVC 5 application. As we know, we can add this attribute to global filters like that:

 f         


        
2条回答
  •  执念已碎
    2021-02-14 15:52

    You should wrap your action filter logic inside a try catch, then inside the catch block, redirect to the Error view and pass the Exception.

    Your only other alternative is to ditch HandleError completely and use the Application_Error event inside Global.asax to manage your error handling. That way you can redirect to your Error action inside there regardless of where the error occured.

提交回复
热议问题