mrb398
mrb398

Reputation: 1317

Apply ActionFilterAttribute to the entire WebAPI?

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?

Upvotes: 9

Views: 4136

Answers (1)

Mukesh
Mukesh

Reputation: 410

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());
          }
}

Upvotes: 16

Related Questions