简体   繁体   English

MVC获取Azure Active Directory身份验证用户的名称和姓氏

[英]MVC Get givenname and surname of Azure Active Directory authenticated user

I'm able to obtain the user name (email format) of the authenticated user using: 我可以使用以下方法获取经过身份验证的用户的用户名(电子邮件格式):

var autenticateduser = HttpContext.User.Identity.Name;

Using QuickWatch window I am able to find the givenname and surname using the following expression. 使用QuickWatch窗口我可以使用以下表达式查找给定名称和姓氏。 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]

How about 怎么样

ClaimsPrincipal cp = ClaimsPrincipal.Current;
string welcome = string.Format("Welcome, {0} {1}!", cp.FindFirst(ClaimTypes.GivenName).Value, cp.FindFirst(ClaimTypes.Surname).Value);

This way you can get non standard claims also, you just need to know the name of the key, obtainable for example from the openidconnect YOURDOMAIN/.well-known/openid-configuration JSON response. 通过这种方式,您还可以获得非标准声明,您只需要知道密钥的名称,例如可以从openidconnect YOURDOMAIN / .well-known / openid-configuration JSON响应中获取。

Hello @User.Claims.Single(a => a.Type == " http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname ").Value! Hello @ User.Claims.Single(a => a.Type ==“ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname ”)。值!

system.security.claims.claimsprincipal.claims API reference system.security.claims.claimsprincipal.claims API参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Asp.Net MVC中的Active Directory获取当前经过Windows身份验证的用户 - Get current windows authenticated user from Active Directory in Asp.Net MVC Asp.Net Mvc 5 Azure Active Directory在服务器上获取并保存用户配置文件图像 - Asp.Net Mvc 5 Azure Active Directory Get and save user profile image on server 如何在 ASP.NET MVC 中获取/设置自定义 Azure Active Directory B2C 用户属性? - How to get/set custom Azure Active Directory B2C user attributes in ASP.NET MVC? 如何确认用户是否已经在Active Directory中进行了身份验证? - How to confirm if a user is already authenticated in Active DIrectory? MVC5如何遍历Azure活动目录用户组 - MVC5 how to iterate through an azure active directory user group 使用Azure Active Directory对用户进行身份验证后执行代码 - Executing code after user has been authenticated using Azure Active Directory asp.net mvc如何显示GivenName和Surname而不是Name - asp.net mvc How can I show GivenName and Surname instead of Name MVC Core + Azure Active Directory 从 GraphAPI 获取组 - MVC Core + Azure Active Directory Get Groups from GraphAPI 无法从Azure Active Directory获取用户组 - Unable to get user groups from Azure Active Directory 如何获取Azure Active Directory角色或用户组 - How to get Azure Active Directory role or user group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM