简体   繁体   中英

Connect to LDAP server using C#

We have following server details:

Server: CN=HQITSA01,OU=Domain Controllers,DC=example,DC=net

We don't have username and password.

Our Code:

PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, "example.net");

We have tried above code to connect but it throwing error: The server could not be contacted.

The right instruction should be:

var context = new PrincipalContext(ContextType.Domain, "EXAMPLE", "DC=EXAMPLE,DC=net");

where EXAMPLE here is the NETBIOS name for the domain. You can also try with

var context = new PrincipalContext(ContextType.Domain, null);

to connect to the current domain, if example.net is you current domain.

Check the documentation of PrincipalContext object at this link for further details or this SO question .

BTW, "the server could not be contacted" looks like a simple connectivity problem.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM