猿问

ASP.NET Core:如果通过IAuthorizationPolicyProvider获取

AuthorizeFilter 添加 AuthorizationPolicy 的代码如下:

services.AddMvc(o =>
    {        var policy = new AuthorizationPolicyBuilder()
            .RequireRole(ROLE_NAME)
            .Build();
        o.Filters.Add(new AuthorizeFilter(policy));
    });

请问如何通过 IAuthorizationPolicyProvider 接口获取上面添加的 AuthorizationPolicy ?


慕丝7291255
浏览 1155回答 1
1回答

莫回无

AuthorizeFilter 添加的 AuthorizationPolicy 是无法通过 IAuthorizationPolicyProvider 获取到的,需要在 services.AddAuthorization 中通过 AddPolicy 添加services.AddAuthorization(options => {     options.AddPolicy(POLICY_NAME, policy =>     {         policy.RequireAuthenticatedUser().RequireRole(ROLE_NAME);     }); });
随时随地看视频慕课网APP
我要回答