微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.";
    }
}

原文地址:https://www.jb51.cc/csharp/101000.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐