为了账号安全,请及时绑定邮箱和手机立即绑定

从HttpContext.User.Claims中提取值

从HttpContext.User.Claims中提取值

C#
拉丁的传说 2021-05-14 09:27:15
我正在尝试从中提取电子邮件地址,HttpContext.User.Claims并且希望寻求帮助,以找到一种更好的方式对此进行编码(也许使用LINQ?)我现在的操作方式似乎很琐。var userClaimsList = HttpContext.User.Claims.ToList();// List is of varying length but email is always 3rd from the bottom.int emailPosition = userClaimsList.Count()-3; string searchString = "preferred_username: "; // dirtyEmail = "preferred_username: xyz@emailcom"string dirtyEmail = userClaimsList[emailPosition].ToString();string cleanEmail = dirtyEmail.Replace(searchString, "").ToLower().Trim();我尝试了另一篇文章中推荐的LINQ解决方案,但收到错误消息Operator == cannot be applied to operands of type 'Claim' and 'string'。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1294 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信