[英]Determine if a logged in user is a member of an AD group, in a web app deployed to Azure
[英]Web App picks up logged in user name when running localhost but not when deployed
我有一个 Webforms 应用程序,我正在对其进行调整以使用 Azure AD 来获取用户名。 我使用以下内容来指导我:
在本地主机上运行一切正常。 当我将它部署到 xxxx.azurewebsites.net 时,该站点出现,但没有任何 AAD 信息可用。 我不确定从哪里开始诊断。
我已经更改了 web.config 文件的 clientID 和 TenantID 值以及上面链接中描述的重定向 URI。
只是尝试使用: HttpContext.Current.User.Identity.Name 和 HttpContext.Current.User.Identity.IsAuthenticated
HttpContext.Current.User.Identity.Name 在 azurewebsites.net 上返回空白,但返回我用来向 Microsoft 进行身份验证的 email 地址。
提前感谢您的帮助!
假设您已正确配置它。 您能否尝试以下方法来获取索赔价值:
var userClaims = User.Identity as System.Security.Claims.ClaimsIdentity;
//You get the user’s first and last name below:
ViewBag.Name = userClaims?.FindFirst("name")?.Value;
// The 'preferred_username' claim can be used for showing the username
ViewBag.Username = userClaims?.FindFirst("preferred_username")?.Value;
// The subject/ NameIdentifier claim can be used to uniquely identify the user across the web
ViewBag.Subject = userClaims?.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value;
// TenantId is the unique Tenant Id - which represents an organization in Azure AD
ViewBag.TenantId = userClaims?.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid")?.Value;
另外,请查看以下链接以获取更多参考:
https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-asp-webapp
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.