DotnetCore : OnException method in a custom filter is called two times

Viewed 3302

I am using dotnet core and have created a custom exception filter to handle exceptions. The problem i face is that in case of exceptions , the onException method in the custom filter is called two times. Below is the code :

   public class CustomExceptionFilter : ExceptionFilterAttribute
     {
            public override void OnException(ExceptionContext context)
                 {
                    // Code 
                    base.OnException(context);
                 }
     }

Controller Code is :

         [CustomExceptionFilter]   
         public class MyController : Controller
         {
             // Raise an exception in any apis
         }

Why onException is called two times?

2 Answers

Another scenario that can cause this is adding the attribute in two places:

I had this:

config.Filters.Add( new StandardExceptionHandlingAttribute() );

AND this:

  [StandardExceptionHandling]
  public async Task<int?> ....
Related