【问题标题】:IIS not picking up Windows UserIIS 未获取 Windows 用户
【发布时间】:2016-08-03 17:06:31
【问题描述】:

我制作了一个在右上角显示 Windows 用户名的 Web 应用程序。 如果我在 localhost:5903/index.aspx 上打开 webapp,我会得到正确的 Windows 用户。 像这样 -


但是如果我打开 localhost/db/index.aspx 我会得到 IIS AppPool User -


这里的 db 是我的应用所在的目录。

我不知道为什么会这样。我希望本地主机也显示正确的用户名。

我的 IIS 树,这里 DB(1) 是我的 webapp -

我选择 Windows 身份的 C# 代码 -

<li><% string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;%>
<a><%= userName %></a>
</li>

【问题讨论】:

    标签: c# asp.net iis webforms


    【解决方案1】:

    您需要在 IIS 中设置站点仅用于 Windows 身份验证并关闭匿名。

    为您的站点进入 IIS,然后在“功能视图”下。

    然后在 IIS 类别下 > 身份验证 > 将 Windows 身份验证设置为启用,将所有其他(匿名....其他)设置为禁用。

    而不是...

    System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    

    使用

     HttpContext.Current.User.Identity.Name;
    

    【讨论】:

    • Windows 身份验证已启用。我禁用了匿名。不用找了。仍在获取 IIS AppPool
    • 更新了上面的答案.. 使用 HttpContext.Current.User.Identity.Name;
    • 成功了!你能告诉我有什么区别吗?为什么它不能与 localhost 一起使用?
    • PirateX。 LocalHost(与 Studio Server 没有在 windows auth 下运行)这篇文章很好地回答了它。 stackoverflow.com/questions/5402249/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 2020-03-19
    相关资源
    最近更新 更多