[英]Get the details of currently logged in user
I am making an application where the authentication to that is bind to Azure Active Directory. 我正在制作一个将身份验证绑定到Azure Active Directory的应用程序。
I need to get the first name and last name of logged in user. 我需要获取已登录用户的名字和姓氏。 Currently I am able to get username by using
目前,我可以通过使用获取用户名
public string name
{
get
{
return HttpContext.Current.User.Identity.Name;
}
}
It returns me "Subham.kumar@nathcorp.com", but I don't need the whole username. 它返回“ Subham.kumar@nathcorp.com”,但我不需要整个用户名。
You can use Claims 您可以使用声明
foreach (Claim cl in ((ClaimsIdentity)(User.Identity)).Claims)
{
switch (cl.Type)
{
case ClaimTypes.Email:
currentUser.Mail = cl.Value;
break;
case ClaimTypes.Name:
case ClaimTypes.Surname:
currentUser.Name = cl.Value;
break;
case ClaimTypes.GivenName:
currentUser.FirstName = cl.Value;
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.