在ASP.NET Core 3中更新身份验证cookie 3

发布于 2025-01-26 20:16:38 字数 534 浏览 3 评论 0原文

在ASP.NET Core 3应用中,我使用没有身份的身份验证cookie。这是用户登录时的代码。

string securityStamp = Guid.NewGuid().ToString();
var userClaims = new List<Claim>()
{
  new Claim("id", id_user.ToString()),
  new Claim("securityStamp", securityStamp),
}                       
var grantMyIdentity = new ClaimsIdentity(userClaims, "User Identity");
var userPrincipal = new ClaimsPrincipal(new[] { grantMyIdentity });
await HttpContext.SignInAsync(userPrincipal);

在某个时候,我想在不使用户登录并再次登录的情况下更新cookie的安全stamp。 我该如何为用户透明地做到这一点?

In ASP.net CORE 3 app, I use authentication cookie without Identity. Here is the code when a user log in.

string securityStamp = Guid.NewGuid().ToString();
var userClaims = new List<Claim>()
{
  new Claim("id", id_user.ToString()),
  new Claim("securityStamp", securityStamp),
}                       
var grantMyIdentity = new ClaimsIdentity(userClaims, "User Identity");
var userPrincipal = new ClaimsPrincipal(new[] { grantMyIdentity });
await HttpContext.SignInAsync(userPrincipal);

At some point, I would like to update the securityStamp of the cookie without making the user log out and log in again.
How can I do this transparently for the user?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文