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

标签 c# asp.net iis iis-8

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

System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3)

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

请帮助我了解我哪里出错了?

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

网络配置:

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

关于c# - 无法获取当前用户标识值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48705441/

相关文章:

c# - 为什么我不能更改代码中的音量?

javascript - jquery 工具提示在 ie 10 中不起作用

asp.net - 如何从单独的 .NET 应用程序获取当前上下文或用户身份?

c# - Dapper - 通过构造函数处理具有只读字段的 ddd 实体的自定义映射

c# - 在 C# 中为 Win 8 Metro App 举办 Button 事件

c# - 为什么 visual studio .net 2008 添加 global.asax 文件后会失去调试能力?

asp.net-mvc - 我的应用程序中未加载图像、css 和 js 文件

c# - 无法加载文件或程序集。在 IIS 8.0 上运行的 32 位程序集

asp.net - 如何自动附加VS到另一个进程进行调试?

c# - Azure服务总线使用.net sdk按id删除队列消息