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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With