Handling exceptions in global.asax ASP.NET MVC

前端 未结 3 1234
梦如初夏
梦如初夏 2021-02-15 14:15

I have code which is catching all exceptions in Global.asax

 protected void Application_Error(object sender, EventArgs e) 
        {
            System.Web.HttpC         


        
3条回答
  •  盖世英雄少女心
    2021-02-15 14:47

    I'd take a different tack and put use an attribute on your controllers (or base controller if you have one)

     public class HandleErrorAttributeCustom : HandleErrorAttribute
        {
           public override void OnException(ExceptionContext context)
            {
                //you can get controller by using
                context.Controller.GetType()
    
                //however, I'd recommend pluggin in Elmah here instead 
                //as it gives this easily and also can has filtering
                //options that you want
    
            }
    }
    

提交回复
热议问题