【问题标题】:Get Active Directory user from client request, server side?从客户端请求、服务器端获取 Active Directory 用户?
【发布时间】:2013-02-22 19:55:41
【问题描述】:

我有一个在 IIS 7.5 上运行的自定义 HTTP 模块,请求将来自同一 Active Directory 环境中的不同机器。 我是否可以在运行服务器端的 HTTP 模块中从请求(或查找,如果我知道 LDAP 路径?)中获取当前用户(他们的 AD 名称?)?

我不是 AD 专家,但我查看了来自模块中 HTTPApplication 实例(见下文)的不同属性,但没有看到任何明显的东西。

Private Sub AuthenticateRequest(sender As Object, e As EventArgs)

        Dim oHttpApplication As HttpApplication = CType(sender, HttpApplication)
        '...
        ' Get AD Info from oHttpApplication.Request?
        '...
End Sub

有谁知道这是否可能或知道实现此目的的方法?

更新:

我在下面添加了我的解决方案。

【问题讨论】:

  • ...在反对票后发表评论会很好。

标签: iis active-directory httpmodule


【解决方案1】:

我的解决方案 - 在 VB.NET 中:

Dim username As String = Thread.CurrentPrincipal.Identity.Name

注意:我的链接中问题的答案继续使用PrincipalContextUserPrincipal 对象,但对于我的场景,我只需要用户名。我还想指出,在测试该解决方案时,这一行:

pc = new PrincipalContext(ContextType.Domain, "active.directory.domain.com")

没有域对我来说也可以正常工作:

pc = new PrincipalContext(ContextType.Domain)

因此希望这对将来的某人有所帮助!

【讨论】:

    【解决方案2】:

    修改 IIS 设置:

    在 IIS 中禁用匿名身份验证和启用 windows 身份验证。

    修改 Web 应用配置文件:

    启用模拟

    <configuration>
      <system.web>
        <identity impersonate="true"/>
      </system.web>
    </configuration>
    

    C# 代码:

    using System.Security.Principal
    
    
    var user = WindowsIdentity.GetCurrent().Name;
    

    【讨论】:

    • 谢谢。不过我试过了。对我来说,它返回绑定到服务器上运行的 ApplicationPoolIdentity 帐户的用户。我需要知道谁在发送请求(即来自客户端)。
    • 我已经修改了我的答案。如果用户在同一个局域网中,这应该可以工作。
    • 再次感谢 - 但我已经设置了模拟。请查看我找到的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2019-05-16
    • 2020-03-15
    • 2010-10-27
    • 1970-01-01
    • 2014-09-08
    相关资源
    最近更新 更多