0

I'm currently trying to connect to a remote LDAP-Server. For that, I'm trying to figure out the domain with:

DirectoryEntry entry = new DirectoryEntry("LDAP://141.83.80.30/lam/RootDSE");

Unfortunately, I'm confronted with the error:

System.DirectoryServices.DirectoryServicesCOMException: 'An invalid dn-syntax was provided'

Muhammad Hannan
  • 2,389
  • 19
  • 28
Lenny Will
  • 549
  • 1
  • 4
  • 11
  • You need to provide the OU DN in format mentioned [here](https://stackoverflow.com/questions/1405011/ldap-directory-entry-in-net-not-working-with-ou-users) – Muhammad Hannan May 02 '19 at 11:21
  • @MuhammadHannan Ok, but since I'm trying to work with a remote ldap, I need to add the ip at the beginning right? With the format: `DirectoryEntry entry = new DirectoryEntry("LDAP://141.83.80.30/ou=People,dc=domain,dc=com")` – Lenny Will May 02 '19 at 11:26
  • Yes, see my answer. – Muhammad Hannan May 02 '19 at 11:28

1 Answers1

0

You can use below snippet for remote LDAP connection.

DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://example.com");
directoryEntry.Path = "LDAP://OU=Specific Users,OU=All Users,OU=Users,DC=example,DC=com";
Muhammad Hannan
  • 2,389
  • 19
  • 28
  • I'm sorry, but the addition doesn't help. I'm using `LDAP://141.83.80.30/OU=Users,DC=example,DC=com` and it still explains, that the DN-Syntax is wrong – Lenny Will May 02 '19 at 13:04
  • You have to change your query like above in example and replace `OU=Users,DC=example,DC=com` with your own OU details. – Muhammad Hannan May 02 '19 at 13:47
  • 1
    I found the solution: Basically @MuhammadHannan's solution is correct, but updating `directoryEntry.Path` overwrites the former path. Thus, one needs to set the path to `LDAP://example.com/OU=specific users,OU=all Users,OU=Users,DC=example,DC=com` – Lenny Will May 06 '19 at 08:45