【问题标题】:Retrieve current user's name from active directoy从活动目录中检索当前用户的名称
【发布时间】:2014-06-04 21:41:14
【问题描述】:

在他们登录网站或自动获得访问权限后,我需要帮助来检索当前用户的姓名,因为他们使用 asp.net 4.0(最好是 vb)登录到域上的计算机

我尝试了以下调用

HttpContext.Current.Profile.UserName

HttpContext.Current.User.Identity.Name

但他们只是返回空白。

我没有使用 Active Directory 的经验,而且我发现的大部分内容都假设程序想要读取、写入和更新目录服务。

更新我现在已经尝试了

Dim id As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim User As WindowsPrincipal = New WindowsPrincipal(id)
Return User.Identity.Name

它返回我的名字为 IIS APPPOOL\ASP.NET V4.0

更新 2

Environment.UserName.ToString()

返回 ASP.NETv4.0

我也变了

在 web.config 中设置为 true,它将 NT AUTHORITY\USR 作为当前用户返回,这与我根据我的搜索所期望的一致。我仍然不确定为什么当 impersonate=false 时系统返回 asp.net apppool 而不是用户名。

【问题讨论】:

    标签: asp.net active-directory user-profile


    【解决方案1】:

    首先确保您的 web.config 配置如下:

    <authentication mode="Windows">
    
    </authentication>
    

    其次,确保 IIS 中的 Web 应用程序配置为使用集成 Windows (NTLM) 身份验证。

    这是一篇不错的文章:http://www.asp.net/mvc/tutorials/older-versions/security/authenticating-users-with-windows-authentication-cs

    【讨论】:

    • 事实证明,IT 部门没有使用正确的东西配置服务器和 IIS,并且在他们安装 Windows 身份验证或在 IIS 中激活它之后,它起作用了...... IT 应该坚持的另一个原因让我们完全控制自己的本地开发服务器...
    • 太棒了!我的努力可以加一吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 2010-11-25
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多