一种由 Microsoft 开发的免费开源 Web 框架,使开发人员能够使用 C# 和 HTML 创建 Web 应用。
请教一下 Blazor web app (.net 9.0) 角色授权的 问题
929Free
661
信誉分
哈喽,工程师们好,我在 ****.razor 页面里 加入 @attribute [Authorize(Roles = "超级管理员")] 语句,
当登录拥有该角色权限的用户 访问 ****.razor 页面时,是正常的, 当登录的用户不拥有 超级管理员 该角色时, 页面就报以下错误了:
An unhandled exception occurred while processing the request.
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action<AuthenticationOptions> configureOptions).
Program.cs:
builder.Services.AddAuthentication();
builder.Services.AddCascadingAuthenticationState();
app.UseAuthentication();
app.UseAuthorization();
我的需求是当没有该角色的用户在访问此页面时, 应该自动跳转到 login.razor 页面, 请问我该如何设置呢?
开发人员技术 | .NET | Blazor
开发人员技术 | .NET | Blazor
登录以回答