简体   繁体   English

LDAP服务器不可用。 C#ASP.net

[英]LDAP server unavailable. C# ASP.net

I am new in LDAP coding. 我是LDAP编码的新手。 I developed following simple code to test my LDAP server but I get the error: "LDAP server is unavailable" . 我开发了以下简单代码来测试我的LDAP服务器,但出现错误:“ LDAP服务器不可用”。 But I get the ping reply in cmd from the LDAP server. 但是我从LDAP服务器收到cmd中的ping答复。 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. 从域字符串中删除ldap。 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);
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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