I would like to implement some custom authentication logic, so I wrote an authentication filter. But for some reason, the AuthenticateAsync just never being called, which makes this attribute no use at all.
I have tested the same code in a normal web api project which works fine. Any ideas why this happens? And how can I debug to find the root cause of this scenario? I got nothing in the CallStack neither.
Here is the controller function:
[HttpPost]
[CustomAuthentication]
public async Task<JsonResult> TestFunc(UserAccount user)
{
//controller logic
return Json("blah");
}
Here is the authentication filter:
public class CustomAuthenticationAttribute : Attribute, IAuthenticationFilter
{
public CustomAuthenticationAttribute()
{
var tt = "does it get in?";
}
public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
{
var req = context.Request; // never being called
//xxx authentication logic
return Task.FromResult(0);
}
}