[英]Apply ActionFilterAttribute to the entire WebAPI?
I've setup a custom ActionFilterAttribute for my WebAPI 我为我的WebAPI设置了一个自定义的ActionFilterAttribute
Is there a way to apply this to all WebAPI controllers at once, versus adding the [ActionFilter] to every single WebAPI controller? 有没有办法将此操作同时应用于所有WebAPI控制器,而不是将[ActionFilter]添加到每个WebAPI控制器?
You can add your action filter attribute to global filters which applies to all API controllers from WebApiConfig class's Register method. 您可以将动作过滤器属性添加到全局过滤器,该过滤器适用于WebApiConfig类的Register方法中的所有API控制器。
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.Filters.Add(new TestFilterAttribute());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.