ASP.NET MVC Global error handling

后端 未结 3 1244
夕颜
夕颜 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:19

    You haven't shown how exactly are you handling the errors in your Application_Error event nor how does your custom HandleAttribute is implemented so it's hard to guess what the problem might be. A common problem to watch for when implementing Application_Error is that you render some error view which itself throws an error. Think for example an error view that depends on a Layout and inside this layout you are calling a Html.Action helper to render the contents of another action that itself does database access and stuff. Your error views should be as static as possible. Ideally you should have a different Layout for them to avoid those kind of situations.

    I may also suggest you taking a look at the following approach for handling errors.

提交回复
热议问题