[英]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.