为什么身份没有显示我的所有声明?

2023-12-09

我正在使用 ASP.NET 身份库。我添加了一个声明,但当我询问所有用户的声明时,我没有得到它。我什至重新启动了我的应用程序,以防它没有立即更新。还是没有运气。

获取索赔的代码:

[CascadingParameter]
private Task<AuthenticationState> AuthenticationStateTask { get; set; } = default!;

private async Task InitializeSchedulerData()
{
        var authenticationState = await AuthenticationStateTask;
        var claims = authenticationState.User.Claims.ToList();

这让我(从调试器):

Count = 5
{http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier: 091a0828-6cc5-4cee-bf3a-a2348872de94}
{http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: [email protected]}
{http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress: [email protected]}
{AspNet.Identity.SecurityStamp: JKNDXBICJOPUYON4DIEZK2OD4RODU5NZ}
{Admin: State:Colorado}

在数据库中,表 AspNetUserClaims 为:

Id  UserId  ClaimType   ClaimValue
1   091a0828-6cc5-4cee-bf3a-a2348872de94    Admin   State:Colorado
2   c3a84b03-c3f3-423d-82cf-2c885aca2233    Admin   Campaign:Hick4Colorado
3   12e37c4f-149e-466b-875a-1965a575f5c9    Admin   Campaign:Frisch4Colorado
4   487e9d8a-58d4-49f8-8100-3e014f914012    Director    Campaign:Frisch4Colorado
5   a00342e5-b7b7-4426-8868-a1c0ff82f96d    Admin   *
10  034225c9-e6ff-408e-be77-f5e292078a0a    Executive   State:Alabama
11  77325df9-6147-46e2-a1c3-0bf0e32ba710    Executive   County:Alabama_Baldwin
12  091a0828-6cc5-4cee-bf3a-a2348872de94    Executive   Campaign:Hick4Colorado

知道为什么找不到新条目吗?两个匹配项的 UserId 条目。

Update:我退出并重新启动 Visual Studio。现在它确实出现了。但为什么需要这样做呢?我需要它立即出现。我该如何做到这一点?

更新2:看起来它需要有SignInManager.RefreshSignInAsync(user);调用以更新 cookie 中保存的用户/声明(这解释了为什么退出 VS 也解决了这个问题)。问题是,您无法在 blazor 代码中调用 SignInManager。

当我需要执行此操作时,调用 OnGet() 中调用的 ASP.NET MVC 页面(与其他 Identity MVC 页面一起放置)是否有任何缺点SignInManager.RefreshSignInAsync(user);然后重定向到我在调用此页面时传递的网址?

我知道我们应该使用 OnPost()。但是没有办法重定向到页面并让它调用 OnPost。因此将其放在 OnGet() 中似乎是唯一的选择。

如果我在 OnGet() 中执行此操作,会导致什么问题或产生安全漏洞?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么身份没有显示我的所有声明? 的相关文章

随机推荐