I have an app service hosted on azure. This is the code that runs on first page that loads.
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
var identity = HttpContext.Current.User.Identity.Name;
lblUserInfo.Text = $"Found User -- > {identity}";
return;
}
else
{
lblUserInfo.Text = "Name Unknown!";
}
}
When I run it locally, it correctly says "Name Unknown" in that label. On Azure the Authentication blade on the app service indicates that the service cannot be accessed without a login. In other words, the app can be accessed by people in the organization.
My understanding from the MSDN documentation is that HttpContext.Current.User can be used to fetch the user's name in the code. This is not working as the identity variable in the code is blank when I host on azure. The website label displays "Found User --> " when it runs on Azure.
What else do I need to do in order to get the user's name in the code?