c# - 在 User.Identity 中返回 NameIdentifier 的错误值
问题描述
我正在使用 Asp.net core 3.1 和 User.Identity 来获取 UserId ,最近我们的一些用户报告了一个问题,他们在登录时看到的是另一个用户帐户,而不是看到自己的帐户。这是我认为导致此问题的代码:
User.Identity.FindFirstValue(ClaimTypes.NameIdentifier);
我使用的扩展:
public static string FindFirstValue(this IIdentity identity, string claimType)
{
var claimsIdentity = identity as ClaimsIdentity;
return claimsIdentity?.FindFirstValue(claimType);
}
public static string FindFirstValue(this ClaimsIdentity identity, string claimType)
{
return identity?.FindFirst(claimType)?.Value;
}
其他信息:
- 缓存未激活
- 用户报告此问题的比例不到 5%
- User.Identity.FindFirstValue(ClaimTypes.NameIdentifier)在 ViewComponent 中使用
解决方案
推荐阅读
- ios - 如何在 iOS 中更改 UIColorPickerViewController 的语言?
- sql - SQL数据操作(添加FK并显示来自不同表的数据)
- php - 使用负载平衡器的 $_SERVER['REMOTE_ADDR'] 的解决方法
- android - 使用单个元素 android studio 获取 Json 数组
- android - 如何将应用内消息仅针对特定用户?
- python - 生成随机复值张量
- javascript - 如何使用 Javascript 创建无格式文件上传?
- android - 如何在具有 X 和 Y 标题的 android 中创建 uiCollectionView 类型的布局并可以绘制数据
- javascript - 文件上传后如何显示关闭图标
- python - 10 的幂在 Python 中无法正常工作:乘以 10**7 不返回与 10e7 相同的结果