views:

421

answers:

2
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.

A: 

Well you get UnauthorizedAccess if you try to login without password and username.

This actually depends on how the LDAP server is configured but this does not seem to allow anonymous access.

I think that the path should be defined without the ip address like LDAP://CN=users,DC=company,DC=ltm,DC=dom but I am not used in .NET so I can't say for sure.

Calmar
+1  A: 

Have you tried it without specifying AuthenticationTypes?

Just like:

DirectoryEntry dir = new DirectoryEntry(path, admin, pass);
Regent
Yes but then I get a DirectoryServicesCOMException which tells me that a unit connected to this machine doesn't work.
remdao
@remdao, is your computer joined to that domain?
Regent
No the computer I'm connicting to has it's own domain. I think that's the problem, thanks for the help :)
remdao
`AuthenticationTypes.ServerBind | AuthenticationTypes.Secure` might work...
Regent