ldap with c#


1)way 1

//Use the servername and port that you setup LDAP Directory Service on
//9605 is the example port here
LdapDirectoryIdentifier ldapDir = new LdapDirectoryIdentifier("servername", 9605);
LdapConnection ldapConn = new LdapConnection(ldapDir);
//You may need to try different types of Authentication depending on your setup
ldapConn.AuthType = AuthType.Basic;
//Update the next line to include the Fully Qualified LDAP name
// of the user along with that user's password
System.Net.NetworkCredential myCredentials =
new System.Net.NetworkCredential("uid=admin,ou=Administrators,
ou=TopologyManagement,o=netscapeRoot", "password");
//This is the actual Connection establishment here

2)way 2

irectoryEntry dirEntry = new DirectoryEntry();
dirEntry.Path = @"LDAP://servername:9605/dc=example,dc=com";
dirEntry.Username = "uid=admin,ou=Administrators,
dirEntry.Password = "password";
dirEntry.AuthenticationType = AuthenticationTypes.ServerBind;