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?
Is there a way to apply this to all WebAPI controllers at once, versus adding the [ActionFilter] to every single WebAPI controller? Take a look here: stackoverflow.com/questions/14982049/… You can add your action filter attribute to global filters which applies to all API controllers from WebApiConfig class's Register method.
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 ()); } }
Web API Filters. Web API includes filters to add extra logic before or after action method executes. Filters can be used to provide cross-cutting features such as logging, exception handling, performance measurement, authentication and authorization.
An action filter is an attribute that you can apply to a controller action -- or an entire controller -- that modifies the way in which the action is executed. The ASP.NET MVC framework includes several action filters: OutputCache – This action filter caches the output of a controller action for a specified amount of time.
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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With