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();
The below code snippet works fine but it only confirms Authentication for me:Please Correct Me ! As I am New to LDAP I don't know whats the replacement code for above circumstance.
- using (LdapConnection ldap = new LdapConnection(ConfigurationManager.ConnectionStrings["ADConnectionString"].ConnectionString))
- {
- ldap.AuthType = AuthType.Basic;
- ldap.SessionOptions.ProtocolVersion = 3;
- // Distinguished name is reuired to pass to the bind method
- string distinguishedName = "cn=" + username + ",ou=Users,dc=domain,dc=com";
- ldap.Bind(new NetworkCredential(distinguishedName, password));
- }
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.
Nitin SontakkePosted Feb 28, 2017, 12:50 AM
Ramesh PalanivelPosted Feb 28, 2017, 12:47 AM
Vaibhav DeshmukhPosted Feb 28, 2017, 12:27 AM
Ramesh PalanivelPosted Feb 27, 2017, 10:18 AM
{
var userDetails = new UserDetails();
try
{
//TO:DO Web Config AD
string DomainPath = "LDAP://10.10.10.131"; // IP address of active directory server machine
DirectoryEntry searchRoot = new DirectoryEntry(DomainPath, UserName, Password, AuthenticationTypes.Secure);
DirectorySearcher search = new DirectorySearcher(searchRoot);
SearchResult result = search.FindOne();
if (result != null)
{
userDetails = _repository.GetValidUserDetails(UserName, Password, true);
}
return userDetails;
}
catch (Exception ex)
{
//TODO : call the LOG to pass the exception
return userDetails;
}
}
Vaibhav DeshmukhPosted Feb 27, 2017, 7:38 AM
Nitin SontakkePosted Feb 27, 2017, 7:28 AM