MVC获取Azure Active Directory身份验证用户的给定名称和姓氏 [英] MVC Get givenname and surname of Azure Active Directory authenticated user
本文介绍了MVC获取Azure Active Directory身份验证用户的给定名称和姓氏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下方法获取经过身份验证的用户的用户名(电子邮件格式):
I'm able to obtain the user name (email format) of the authenticated user using:
var autenticateduser = HttpContext.User.Identity.Name;
使用QuickWatch窗口,我可以使用以下表达式找到给定名称和姓氏.有没有更干净的方法来获取此信息?
Using QuickWatch window I am able to find the givenname and surname using the following expression. Is there a more clean way to obtain this info?
(new System.Linq.SystemCore_EnumerableDebugView<System.Security.Claims.Claim>(((System.Security.Claims.ClaimsIdentity)(HttpContext.User.Identity)).Claims)).Items[5]
推荐答案
关于
ClaimsPrincipal cp = ClaimsPrincipal.Current;
string welcome = string.Format("Welcome, {0} {1}!", cp.FindFirst(ClaimTypes.GivenName).Value, cp.FindFirst(ClaimTypes.Surname).Value);
这篇关于MVC获取Azure Active Directory身份验证用户的给定名称和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文