9

I've setup a custom ActionFilterAttribute for my WebAPI

Is there a way to apply this to all WebAPI controllers at once, versus adding the [ActionFilter] to every single WebAPI controller?

mrb398
  • 1,277
  • 4
  • 24
  • 32
  • Take a look here: https://stackoverflow.com/questions/14982049/mvc-4-web-api-register-filter – kiziu Jun 26 '17 at 15:31

1 Answers1

16

You can add your action filter attribute to global filters which applies to all API controllers from WebApiConfig class's Register method.

public static class WebApiConfig
{
          public static void Register(HttpConfiguration config)
          {
                 // Web API configuration and services
                    config.Filters.Add(new TestFilterAttribute());
          }
}
Mukesh
  • 410
  • 5
  • 12