【发布时间】:2021-06-29 11:41:59
【问题描述】:
因此,当我将基于策略的授权添加到 Startup.cs 文件,然后将 AuthorizeView 添加到我的 Blazor 页面时,我收到一个错误:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The AuthorizationPolicy named: 'SuperAdmin' was not found.
System.InvalidOperationException: The AuthorizationPolicy named: 'SuperAdmin' was not found.
at Microsoft.AspNetCore.Authorization.AuthorizationPolicy.CombineAsync(IAuthorizationPolicyProvider policyProvider, IEnumerable`1 authorizeData)
at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.IsAuthorizedAsync(ClaimsPrincipal user)
at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle) blazor.webassembly.js:1:14889
但在我的启动中:
services.AddAuthorization(o =>
{
o.AddPolicy("SuperAdmin", policy => policy.RequireClaim("SuperAdmin"));
o.AddPolicy("CountyAdmin", policy => policy.RequireClaim("CountyAdmin"));
});
当我查看用户的“声明”时,没有显示来自数据库的声明。不过他们在那里。
那么,为什么,如果我在启动时声明了策略,那么标有上述策略的剃须刀页面会给我这个错误?
谢谢大家!!!
【问题讨论】:
-
你能展示一个简单的演示吗?
-
我遇到了同样的问题。我在剃刀页面顶部有以下内容:@attribute [Authorize(Policy = "SuperAdmin")]
标签: asp.net-core authorization claims-based-identity blazor-webassembly