我在azure上托管了一个应用程序服务.这是在加载的第一页上运行的代码.
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!";
}
}
当我在本地运行它时,它在标签中正确地显示"名称未知".在Azure上,应用程序服务上的身份验证Blade 表明,没有登录就无法访问该服务.换句话说,该应用程序可以被组织中的人员访问.
我对MSDN documentation的理解是HttpContext.现在的用户可用于获取代码中的用户名.这不起作用,因为当我在azure上托管时,代码中的标识变量为空.网站标签在Azure上运行时显示"Found User --> "
.
What else do I need to do in order to get the user's name in the code?