Im very surprised because I have 5 years ago making LDAP connections but suddenly there is one which I can´t connect to ldap. The LDAP data are:
LDAP: LDAP://172.16.0.181:390/dc=asmet,dc=local
Username: cn=zentyalro,dc=asmet,dc=local
Password: EBsmOpCoIytamGe=Yret
The next is the code that I'm using for authentication:
bool authentic = false;
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://172.16.0.181:390/dc=asmet,dc=local",
@"cn=zentyalro,dc=asmet,dc=local", "EBsmOpCoIytamGe=Yret");
object nativeObject = entry.NativeObject;
authentic = true;
}
catch (DirectoryServicesCOMException ex)
{
}
And the error is:
Invalid DN syntax specified.
Really I don't know why is happening this. The more strange thing is that with any LDAP explorer tool the authentication is possible, but in code not. Why?
I think it is because of your syntax. Try this code below:
bool authentic = false;
using (var context = new PrincipalContext(ContextType.Domain, "172.16.0.181:390", username , password))
{
if (context.ValidateCredentials(username, password) == true)
{
authentic = true;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.