2

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();
    }
}
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120

2 Answers2

0

Decorate your Action or Controller with [OverrideActionFilters]

0

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

DrakonHaSh
  • 831
  • 6
  • 7