AuthorizeFilter 添加 AuthorizationPolicy 的代碼如下:services.AddMvc(o =>
{ var policy = new AuthorizationPolicyBuilder()
.RequireRole(ROLE_NAME)
.Build();
o.Filters.Add(new AuthorizeFilter(policy));
});請問如何通過 IAuthorizationPolicyProvider 接口獲取上面添加的 AuthorizationPolicy ?
1 回答

莫回?zé)o
TA貢獻(xiàn)1865條經(jīng)驗 獲得超7個贊
AuthorizeFilter 添加的 AuthorizationPolicy 是無法通過 IAuthorizationPolicyProvider 獲取到的,需要在 services.AddAuthorization 中通過 AddPolicy 添加
services.AddAuthorization(options => { options.AddPolicy(POLICY_NAME, policy => { policy.RequireAuthenticatedUser().RequireRole(ROLE_NAME); }); });
- 1 回答
- 0 關(guān)注
- 1181 瀏覽
添加回答
舉報
0/150
提交
取消