绕过IAsyncAuthorizationFilter过滤器

时间:2018-07-13 16:08:42

标签: asp.net-core

  public class AuthenticationFilter : IAsyncAuthorizationFilter
{
    public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
    {
        var authToken = context.HttpContext.Request.Headers.ContainsKey("Authorization");
        if (!authToken)
        {
            context.Result = new UnauthorizedResult();
        }
    }
}

此过滤器在每个控制器之前被调用,我想跳过此过滤器进行登录并注册用户控制器。如何在Asp.net Core中执行此操作,我尝试添加AllowAnonymous装饰器,但该方法无效。

在startup.cs

services.Configure<MvcOptions>(options =>
        {
            //TODO: remove in production.
            options.Filters.Add(new CorsAuthorizationFilterFactory("AllowSpecificOrigin"));
            options.Filters.Add(new AuthenticationFilter());
        });

0 个答案:

没有答案