ASP.Net MVC Error handling using Action Filters Attributes

后端 未结 1 936
Happy的楠姐
Happy的楠姐 2021-01-24 04:34

I am trying to implement Error handling using Action Filters Attributes as per ScottGu\'s blog

My code is as follows:

[HandleError]
[HandleError(Exceptio         


        
1条回答
  •  春和景丽
    2021-01-24 05:27

    The action filters are executed one by one. In your case, the problem is probably that the generic HandleError action filter is executed before the specific one.

    You can influence the order of execution by setting the 'Order' property of your action filter:

    [HandleError(Order = 2)]
    [HandleError(Order = 1, ExceptionType = typeof(NullReferenceException), View = "CustomError")]
    public class ArticlesController : Controller
    {
    }
    

    0 讨论(0)
提交回复
热议问题