无法获取当前用户标识值

Aks*_*hay 7 c# asp.net iis iis-8

我有一个Intranet网站,我可以在本地机器上运行时获取用户的身份值.

System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3)
Run Code Online (Sandbox Code Playgroud)

但是当我在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>
Run Code Online (Sandbox Code Playgroud)

IIS设置:

Windows authentication - Enabled
Impersonation  - Enabled
Rest all disabled.

Default app pool - Integrated mode.
Run Code Online (Sandbox Code Playgroud)

537*_*037 7

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  ---+
Run Code Online (Sandbox Code Playgroud)

使用User.Identity.Name来获得登录用户和测试这样的:

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.";
    }
}
Run Code Online (Sandbox Code Playgroud)