ASP.NET MVC Global error handling

后端 未结 3 1247
夕颜
夕颜 2021-02-08 09:37

I have a custom HandleError attribute that deals with errors on the MVC pipeline; I have an protected void Application_Error(object sender, EventArgs e)

3条回答
  •  忘了有多久
    2021-02-08 10:18

    Application_Error might be the recommended way of handling errors in ASP.NET WebForms. But not in MVC.

    We got error filters that take care of errors for us. The problem with the filter is that it only works when a controller has been invoked. Which is the problem for 404 and 401 errors (not found and authorization) and your database connection problem.

    customErrors is the way to go here. I don't see why the redirect should be a problem?

    I'm going through proper error handling in a blog article: http://blog.gauffin.org/2011/11/how-to-handle-errors-in-asp-net-mvc/

提交回复
热议问题