c# – 无法获取当前用户标识值

我有一个Intranet网站,我可以在本地计算机上运行时获取用户的身份值.
System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3)

但是当我在IIS 8.5上部署它时,它发现它是空白的.

请帮我理解我哪里错了?

对于模拟,我们必须使用特定的用户名和密码.

Web.config文件

<system.web>
    <authentication mode="Windows" />
        <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Error/Error.aspx" >
            <error statusCode="404" redirect="~/Pages/Error/404.aspx" />
        </customErrors>
    <identity impersonate="true" userName="user1" password="pass1" />
  </system.web>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>

IIS设置:

Windows authentication - Enabled
Impersonation  - Enabled
Rest all disabled.

Default app pool - Integrated mode.

解决方法

IIS设置应如下所示:
+------------------------------------+
|           Authentication           |
+------------------------------------+
Name                         Status
------------------------     --------
Anonymous Authentication     disabled ---+
ASP.NET Impersonation        Enabled     |
Basic Authentication         Enabled     |__ Both are important
Digest Authentication        disabled    |
Forms Authentication         disabled    |
Windows Authentication       Enabled  ---+

使用User.Identity.Name获取登录用户test like this

protected void Page_Load(object sender,EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        Page.Title = "Home page for " + User.Identity.Name;
    }
    else
    {
        Page.Title = "Home page for guest user.";
    }
}

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...