policyBuilder .RequireClaim("VIPNumber") …" name="description" />
发布:2023/12/7 15:26:28作者:大数据 来源:大数据 浏览次数:383
1 2 3 4 5 6 7 8 9 10 |
services.AddAuthorization(options => { options.AddPolicy( "CanAccessVIPArea", policyBuilder => policyBuilder .RequireClaim("VIPNumber") .RequireClaim("EmployeeNumber") .RequireRole("CEO")); }; }); |
以上三个关系为and关系,如果想实现or关系,那么在configureservice中就得这样
1 2 3 4 5 6 7 8 9 10 11 |
services.AddAuthorization(options => { options.AddPolicy( "CanAccessVIPArea", policyBuilder => policyBuilder.RequireAssertion( context => context.User.HasClaim(claim => claim.Type == "VIPNumber" || claim.Type == "EmployeeNumber") || context.User.IsInRole("CEO")) ); }); |
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4