Apply ActionFilterAttribute to the entire WebAPI?
Asked Answered
O

1

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?

Ocieock answered 26/6, 2017 at 15:17 Comment(1)
Take a look here: #14982549Norword
O
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());
          }
}
Olympie answered 26/6, 2017 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.