[英]Get current windows authenticated user from Active Directory in Asp.Net MVC
[英]MVC Get givenname and surname of Azure Active Directory authenticated user
我可以使用以下方法獲取經過身份驗證的用戶的用戶名(電子郵件格式):
var autenticateduser = HttpContext.User.Identity.Name;
使用QuickWatch窗口我可以使用以下表達式查找給定名稱和姓氏。 是否有更簡潔的方法來獲取此信息?
(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);
通過這種方式,您還可以獲得非標准聲明,您只需要知道密鑰的名稱,例如可以從openidconnect YOURDOMAIN / .well-known / openid-configuration JSON響應中獲取。
Hello @ User.Claims.Single(a => a.Type ==“ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname ”)。值!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.