超级简单的匿名 LDAP

假设有 LDAPv3,但很容易改变它。这是匿名的,未加密的 LDAPv3 LdapConnection 创建。

private const string TargetServer = "ldap.example.com";

实际上创建了三个部分的连接:LdapDirectoryIdentifier(服务器)和 NetworkCredentials。

// Configure server and credentials
LdapDirectoryIdentifier identifier = new LdapDirectoryIdentifier(TargetServer);
NetworkCredential creds = new NetworkCredential();
LdapConnection connection = new LdapConnection(identifier, creds)   
{
    AuthType=AuthType.Anonymous,
    SessionOptions =
    {
        ProtocolVersion = 3
    }
};

要使用连接,像这样的东西会让姓史密斯的人

SearchRequest searchRequest = new SearchRequest("dn=example,dn=com", "(sn=Smith)", SearchScope.Subtree,null);