Blazor
一个免费的开源 Web 框架,使开发人员能够使用 Microsoft 开发的 C# 和 HTML 创建 Web 应用。
35 个问题
哈喽,工程师们好,我在 ****.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 页面, 请问我该如何设置呢?