azure - 在 Web API 控制器中从 Azure AD 获取当前登录的用户详细信息
问题描述
NET Core 3.0 Web API,之前我使用的是 Windows 身份验证。所以在我的控制器中,这是我获取当前登录用户详细信息的方式。
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(ctx, User.Identity.Name);
我已经在 Azure 门户和我的应用程序中为基于 Azure AD 的身份验证设置了所有内容。因此,当我启动应用程序时,它登录成功并返回到我的页面,因为我在门户中设置了replyurl。
但是在返回时,我在ctx变量中没有得到任何东西。我真的相信在使用 Azure AD 时,这可能是实现这一目标的其他方式。请帮我解决这个问题。
解决方案
您应该能够获取详细信息
ViewBag.Name = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Name).Value;
推荐阅读
- iframe - 谷歌忽略索引外部嵌入式 iframe 结构化数据
- reactjs - 与其他图像叠加后如何保存图像?
- sql - 查询 date_time 字段的日期部分。yyyy-mm-dd
- weka - 错误消息:参数行尾,在 weka 中读取 token[EOL]
- r - 任何人都可以帮助我使用 R 包 EcoSimR 和 bipartite 吗?
- php - 不支持的驱动程序 [mysql2]:使用多个数据库时
- python-3.x - 并行化熊猫数据框应用
- powershell - Powershell - 选择文件名而不是完整路径和文件名
- javascript - 如何使用 fetch 正确地控制台记录数据?
- sql - SQL将多个子查询列连接在一起