Using of HandleErrorAttribute in ASP.NET MVC application

淺唱寂寞╮ 提交于 2019-12-04 03:09:21

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.

Matt is right about global.asax... this is the example I followed http://www.digitallycreated.net/Blog/57/getting-the-correct-http-status-codes-out-of-asp.net-custom-error-pages

Then in each view I added: Response.StatusCode = 500; or which ever other code I wanted to show back to the client.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!