Reputation: 112
I have a web API that is authenticated by Azure's AD. Within the API codes, what is the code to retrieve the username of the authenticated user?
Upvotes: 4
Views: 6377
Reputation: 3307
Using System.Web.HttpContext.Current.User.Identity.Name
will retrieve the email address that they have used to log in with.
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.
Upvotes: 5