简体   繁体   中英

Remove all action filter attributes in a derived web api controller

I have a simple web api controller where action methods are decorated with various built in and custom filters.Now I want to create another controller which inherits from the first one, how can I remove\\bypass all the action filters on the derived controller?

Base controller:

public class ValuesController : ApiController
{
    // GET api/values
    [Authorize]
    [CustomFilter]
    public virtual IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }
}

Derived controller:

public class ExtenderController : ValuesController
{
    //Must bypass [Authorize] and [CustomFilter]
    public override IEnumerable<string> Get()
    {
        return base.Get();
    }
}

[OverrideActionFilters]装饰你的动作或控制器

Derived controller:

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();
    }
}

see link(1) and link(2) for details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM