简体   繁体   中英

LDAP server unavailable. C# ASP.net

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);
            }
        }

You have to just provide the name. Remove the ldap from the domain string. For eg

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);
            }
        }

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