Click here to Skip to main content
13,353,706 members (58,231 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,
I have to connect to local ldap which is on apache server. I use your code like this

private string sDomain = "ldap://localhost:10389";
   private string sDefaultOU = "ou=users,ou=system";

   private string sServiceUser = @"uid=admin,ou=system";
   private string sServicePassword = "secret";

PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, sServiceUser, sServicePassword);


But I didn't get connected, anything wrong I am doing.
Posted 24-Aug-12 1:49am
Updated 24-Aug-12 12:40pm
Wendelius366.9K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Its bit late to give you my solution - but It would be useful for others if the encounter the same issue.

Possible solution would be as follows
private string sDomain = "localhost:10389";
//sDomain is ServerName or Hosename or just IP address
//You had it with ldap://

private string sDefaultOU = "ou=users,ou=system";

private string sServiceUser = @"uid=admin,ou=system";
private string sServicePassword = "secret";

PrincipalContext oPrincipalContext = new PrincipalContext
   (ContextType.Domain, sDomain, sDefaultOU, sServiceUser, sServicePassword);


Hope this helps and it worked for me.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You are not passing the right parameters.
The five parameter constructor overload's third parameter is not default OU, it is default container! Thus you need to qualify it with DC-s. And the user name parameter need not be qualified with OU, use just the "admin" string.
Check also here: Using System.DirectoryServices.AccountManagement[^]
  Permalink  
Comments
mayankkarki 27-Aug-12 3:34am
   
Thanks for reply,
But I didn't get succeed.I tried to connect with michigan open ldap server

private string sDomain = "LDAP://ldap.itd.umich.edu:389";
private string sDefaultOU = "ou=System Groups,ou=Groups,dc=umich,dc=edu";
private string sServiceUser = "cn=Directory Manager,o=University of Michigan,c=us";
private string sServicePassword = "";

First I use this and works perfectly
DirectoryEntry de = new DirectoryEntry(sDomain + "/" + sDefaultOU, sServiceUser, sServicePassword,AuthenticationTypes.ServerBind);
DirectorySearcher ds = new DirectorySearcher(de);
SearchResult sr = ds.FindOne();

But with principalcontext got same error "server could not be contacted."
PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain,sDefaultOU,ContextOptions.ServerBind|ContextOptions.Negotiate, sServiceUser, "");
Is there something missing?
Zoltán Zörgő 27-Aug-12 5:08am
   
For PrincipalContext, the sDomain should be only the dns name (no protocol, no port).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 30 Apr 2014
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100