我有一个简单的web api控制器,其中动作方法用各种内置和自定义过滤器进行修饰。现在我想创建另一个继承自第一个的控制器,如何删除\绕过派生的所有动作过滤器控制器?
基础控制器:
public class ValuesController : ApiController
{
// GET api/values
[Authorize]
[CustomFilter]
public virtual IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
派生控制器:
public class ExtenderController : ValuesController
{
//Must bypass [Authorize] and [CustomFilter]
public override IEnumerable<string> Get()
{
return base.Get();
}
}
答案 0 :(得分:1)
使用 [OverrideActionFilters]
装饰您的操作或控制器答案 1 :(得分:0)
派生控制器:
public class ExtenderController : ValuesController
{
[OverrideAuthorization] //Bypass [Authorize] (Bypass IAuthorizationFilter)
[OverrideActionFilters] //Bypass [CustomFilter] if inherited from IActionFilter. If not, write your own bypass filter. See an example at link (1) below
public override IEnumerable<string> Get()
{
return base.Get();
}
}