【问题标题】:ldap server is unavailableldap 服务器不可用
【发布时间】:2017-04-04 03:27:06
【问题描述】:

我对这个完全陌生

我尝试使用以下代码连接到 ldap 服务器。

PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, "abcdef", "OU=abcdef,DC=avengers,DC=net");

我收到“LDAP 服务器不可用”异常。

我查看了其他建议添加用户名和密码的帖子,但我想使用这个特定的重载方法,它只接受 Context.Domain、Domain 和 Container 参数。

任何建议将不胜感激。

【问题讨论】:

  • 当我做类似的事情时,我也遇到了使用PrincipalContext 对象的问题。通过使用变量,我能够访问 AD 属性。例如:var context = new PrincipalContext(ContextType.Domain, "pc-name", "DC=domain,DC=com", "user", "password"); ; UserPrincipal user = UserPrincipal.FindByIdentity(context, User.Identity.Name);

标签: c# ldap


【解决方案1】:

我认为您没有使用 Active Directory。

PrincipalContext 适用于仅 AD。 如果您的目录是 OpenLDAP/ 任何其他目录,请尝试以下代码

 public static void Main(String[] rags)
    {
        //If you are not sure about username and password, leave below 2 variables as it is
        String username="";        //Change to your username, if you have any
        String passwd="";           //Change to your Password, if you have any

        DirectoryEntry entry = new DirectoryEntry("LDAP://abcedf/OU=abcdef,DC=avengers,DC=net", username, passwd, AuthenticationTypes.None);           
        DirectorySearcher ds = new DirectorySearcher(entry,"ObjectClass=*");

        // Below statement will list all entries immediately below your BaseDN
        foreach (DirectoryEntry c in entry.Children)
        {
            Console.WriteLine("{0}", c.Path);
        }
     }

【讨论】:

    【解决方案2】:

    感谢您的回复。

    我为“域名”参数(第二个参数)传递了错误的值。我发送的是 OU 值而不是域名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      相关资源
      最近更新 更多