通过LDAPS检索可访问的外部Active Directory服务器上的所有用户帐户

时间:2012-02-07 04:53:22

标签: c# active-directory ldap

我需要连接到我可以访问但只能通过LDAPS访问的外部LDAP服务器。

我提供的信息是用户名,服务器,密码。我需要查询和检索所有用户的列表。我有详细信息的格式是

  • 用户名:domain \ username
  • 密码:{密码}
  • 域名:远程。{domain} .net.au

我编写的以下代码将成功验证我的用户帐户,但我现在需要枚举我遇到问题的所有用户。理想情况下,这将是目录中的所有用户,而不是特定OU中的所有用户。同样,我没有这个服务器的任何OU的完全限定路径。服务器有一个自签名证书,这就是为什么在我的例子中我特意告诉它接受证书。

        int port = secured ? 636 : 389;

        LdapConnection connection = new LdapConnection(new LdapDirectoryIdentifier(ldapServer, port, false, false));

        if (secured)
        {
            connection.SessionOptions.ProtocolVersion = 3;
            connection.SessionOptions.SecureSocketLayer = true;
        }


        connection.Credential = new NetworkCredential(username, password);
        connection.AuthType = AuthType.Basic;
        connection.SessionOptions.VerifyServerCertificate += (conn, cert) => { return true; };
        connection.Bind();

        return connection;

1 个答案:

答案 0 :(得分:2)

所以答案是在Performing a Simple Search System.DirectoryServices.Protocols(S.DS.P)简介的样本中:

// create a search filter to find all objects
string ldapSearchFilter = "(&(objectCategory=person)(objectClass=user))";
相关问题