繁体   English   中英

Windows身份验证:用户名未显示在网页上

[英]Windows authentication: User name not displayed on the Web page

我发布了ASP.NET Web Application 4.0并将其移至服务器。 当用户使用Windows authentication登录其计算机,然后转到浏览器中的Web应用程序页面时,其用户名应显示在aspx页面上。

在服务器上, Windows authentication设置为true,并且匿名访问被禁用。

但是,用户名未显示在aspx页面上。 而是显示“ Welcome Not authenticated”。 我有想念吗? 任何指针表示赞赏。

这段代码在SiteMaster.cs中:

public partial class SiteMaster : System.Web.UI.MasterPage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
        {
            divWelcome.InnerHtml = "Welcome " + System.Web.HttpContext.Current.User.Identity.Name;
        }
        else
        {
            divWelcome.InnerHtml = "Welcome " + "Not authenticated";
        }
    }
}

我不知道是否必须在Web.config对其进行修改。 我没有使用登录功能,因为任何人都可以访问该页面:

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>

尝试将其更改为

<authentication mode="Windows" />

这应该修复它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM