超級簡單的匿名 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);