Search code examples
ldapdirectoryentry

LDAP Invalid DN Syntax


string path = "LDAP://192.168.0.20/CN=users,DC=company,DC=ltm,DC=dom";

DirectoryEntry dir = new DirectoryEntry(path, admin, pass, AuthenticationTypes.ServerBind);

object value = dir.Properties["description"].Value;
dir.Properties["description"].Value = "test";
dir.CommitChanges();

The code generates a COMException : "Invalid DN syntax" at dir.Properties["description"].Value

If I don't specify any the username and password and replace the DirectoryEntry initialization with:

DirectoryEntry dir = new DirectoryEntry(path);
dir.AuthenticationType = AuthenticationTypes.ServerBind;

Then I get UnauthorizedAccessException at CommitChanges.

Any ideas on what might be wrong are greatly appreciated.


Solution

  • Have you tried it without specifying AuthenticationTypes?

    Just like:

    DirectoryEntry dir = new DirectoryEntry(path, admin, pass);