web api action filter doesn't invoke, why?

141 Views Asked by At

I've created a webapi filter (it's using Microsoft.AspNet.WebApi.Core):

using System.Web.Http.Filters;
...
public class AuthenticationFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(HttpActionContext actionContext)

.... }

and use it in my controller:

[AuthenticationFilter]
public class MyController : SomeBaseController

than i'm adding into the bootstrpper using:

    _httpConfiguration.Filters.Add(new AuthenticationFilter());

the problem is that OnActionExecuting doesn't firing.

can u assist?

1

There are 1 best solutions below

1
A_kat On

It is not gonna fire if you dont add it to the services

services.AddMvc(options =>
{
    options.Filters.Add(typeof(SampleActionFilter));
});

I suggest to check out this link as well