我正在尝试从中提取电子邮件地址,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'。
相关分类