简体   繁体   English

从.Net Web API中经过Azure身份验证的AD获取用户名

[英]Get user name from Azure authenticated AD in .Net Web API

I have a web API that is authenticated by Azure's AD. 我有一个通过Azure AD认证的Web API。 Within the API codes, what is the code to retrieve the username of the authenticated user? 在API代码中,用于检索已认证用户的用户名的代码是什么?

Using System.Web.HttpContext.Current.User.Identity.Name will retrieve the email address that they have used to log in with. 使用System.Web.HttpContext.Current.User.Identity.Name将检索他们用于登录的电子邮件地址。

As a side note, I am using this to control what the user has access to on the site. 附带说明一下,我正在使用它来控制用户可以在网站上访问的内容。 Because of how I am implementing it, it is more convenient for me to maintain a database of the usernames and their roles. 由于我是如何实现的,因此对于我来说,维护用户名及其角色的数据库更为方便。 However, if you are doing the same thing, it is also worth looking into [Authorize] and maintaining site access that way. 但是,如果您做的是同一件事,也值得研究[Authorize]并以这种方式维护网站访问权限。

暂无
暂无

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

相关问题 .NET Core 2-Web Api-Azure AD-用户为NULL - .NET Core 2 - Web Api - Azure AD - User is NULL 如何从 asp.net web api 中的身份声明获取 JWT 身份验证的登录用户 - How to get JWT authenticated sign-in user from identity claims in asp.net web api Always getting null value in User Details from Azure AD after authentication .NET Core (3.0) Web API - Always getting null value in User Details from Azure AD after authentication .NET Core (3.0) Web API 如何从 C# MVC .net 核心中的用户名(身份名称)获取 Azure AD 用户组名称? - How to get the Azure AD User Group Name from User Name (Identity Name) in C# MVC .net core? Azure AD:从其他 .net Core Web API 调用 .net Core Web API - Azure AD: Call .net Core Web API from other .net Core Web API 获取使用 Azure AD 进行身份验证的 ASP.NET Core Web 应用程序的用户信息(高级) - Get user info of asp.net core web app which authentificated with Azure AD(advanced) 在 .NET 5 Web API 中动态连接到多个数据库(取决于经过身份验证的用户) - Connecting to multiple databases, dynamically (depending on the authenticated user) in an .NET 5 Web API ASP.Net Core - Web API 可通过 PowerBI 和 Z3A580F1422036773F5F0BC30898ADF 访问 - ASP.Net Core - Web API to get accessed via PowerBI and Azure AD 使用 Azure AD 验证返回 401 - Sending a GET request to an ASP.NET Core Web Application API using Azure AD Authentication returns 401 如何从Azure AD获取用户属性 - How to get user properties from Azure AD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM