Reputation: 245
I am new in LDAP coding. I developed following simple code to test my LDAP server but I get the error: "LDAP server is unavailable" . But I get the ping reply in cmd from the LDAP server. Any body can help?
string domain= "ldaps://SomeDomainName.com:636";
PrincipalContext AD = new PrincipalContext(ContextType.Domain,domain);
UserPrincipal u = new UserPrincipal(AD);
PrincipalSearcher search = new PrincipalSearcher(u);
foreach (UserPrincipal result in search.FindAll())
{
if (result != null && result.DisplayName != null)
{
DropDownList1.Items.Add(result.DisplayName);
}
}
Upvotes: 1
Views: 5504
Reputation: 101
You have to just provide the name. Remove the ldap from the domain string. For e.g.
string domain= "SomeDomainName.com:636";
PrincipalContext AD = new PrincipalContext(ContextType.Domain,domain);
UserPrincipal u = new UserPrincipal(AD);
PrincipalSearcher search = new PrincipalSearcher(u);
foreach (UserPrincipal result in search.FindAll())
{
if (result != null && result.DisplayName != null)
{
DropDownList1.Items.Add(result.DisplayName);
}
}
Upvotes: 2