【问题标题】:Apply ActionFilterAttribute to the entire WebAPI?将 ActionFilterAttribute 应用于整个 WebAPI?
【发布时间】:2017-06-26 15:17:41
【问题描述】:

我已经为我的 WebAPI 设置了一个自定义 ActionFilterAttribute

有没有办法一次将它应用于所有 WebAPI 控制器,而不是将 [ActionFilter] 添加到每个 WebAPI 控制器?

【问题讨论】:

标签: c# .net asp.net-web-api actionfilterattribute


【解决方案1】:

您可以通过 WebApiConfig 类的 Register 方法将您的操作过滤器属性添加到适用于所有 API 控制器的全局过滤器。

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

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多