ant-design-blazor / ant-design-blazor/ant-design-pro-blazor
使用 ReuseTabs 组件时,通过级联传入 RouteData 的方式会导致 AuthorizeRouteView 失效。
- 主要语言
- HTML
- 星标
- 834
- 派生
- 146
- PR 合并指标
- 30 天内没有已合并 PR
描述
## 操作步骤:
1.使用 dotnet new antdesign -o MyAntDesignAppSimple 创建模板
2.添加文件 PersistingRevalidatingAuthenticationStateProvider
```
internal sealed class PersistingRevalidatingAuthenticationStateProvider : AuthenticationStateProvider
{
public override Task GetAuthenticationStateAsync()
{
//var cI = new ClaimsIdentity("test");
//cI.AddClaim(new Claim(ClaimTypes.Name, "admin"));
//cI.AddClaim(new Claim(ClaimTypes.Email, "admin@test"));
//var cP = new ClaimsPrincipal(cI);
//var state = new AuthenticationState(cP);
//var task = Task.FromResult(state);
//NotifyAuthenticationStateChanged(task);
//return task;
return Task.FromResult(new AuthenticationState(new ClaimsPrincipal()));
}
}
```
3. 在MyAntDesignAppSimple .Program.cs中添加以下内容
```
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped();
```
4. 添加一个需要权限的页面
```
@page "/counter"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
Counter
Counter
没权限
有权限Hello @context.User.Identity?.IsAuthenticated.ToString();
Current count: @currentCount
Click me
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
```
5. 将Routes文件替换为以下内容
```
没权限路由
```
## 结果依旧可以导航到该页面

## 后续
注释包裹AuthorizeRouteView 的CascadingValue,并向 ReuseTabs 组件传入 Body 参数后恢复正常

贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。