Hi,
I am badly stucked in implementing LDAP Authentication.
My moto is to find OU or(Groups) based on Username.Means find a particular group for user based on Username.I am trying below way but not getting what I expecting.Since, my credentials are valid it throws an exception "The user name or password is incorrect.":
Snap 1:
- DirectoryEntry entry = new DirectoryEntry("LDAP://IP Address:Port/CN=Users,DC=domain,DC=com",username,password);
- DirectorySearcher ds = new DirectorySearcher(entry);
- ds.Filter = "(&(objectClass=user)(cn=" + username + "))";
- SearchResult results = ds.FindOne();
Snap 2 :The below code snippet works fine but it only confirms Authentication for me:
- using (LdapConnection ldap = new LdapConnection(ConfigurationManager.ConnectionStrings["ADConnectionString"].ConnectionString))
- {
- ldap.AuthType = AuthType.Basic;
- ldap.SessionOptions.ProtocolVersion = 3;
-
- string distinguishedName = "cn=" + username + ",ou=Users,dc=domain,dc=com";
- ldap.Bind(new NetworkCredential(distinguishedName, password));
- }
Please Correct Me ! As I am New to LDAP I don't know whats the replacement code for above
circumstance.
1. Can I use any LDAP conection object or property so that I need not create any DirectoryEntry parameter (String Path,String Username,String password) ?
2. I have pair of two credentials set. One for Connection string to LDAP server and second one is for user. I tried both . But didn't find any way out.
3. How to create connection string for LDAP or DirectoryEntry as connection parameter.?
Thanks In advance.