【问题标题】:LDAP C# error when trying to connect尝试连接时出现 LDAP C# 错误
【发布时间】:2014-08-20 19:07:36
【问题描述】:

尝试连接到 LDAP 服务器时,我不断收到以下错误。用户名或密码不正确。 它发生在 .FindOne() 如果我使用 AuthenticationTypes.Encryption 我得到一个错误:服务器无法运行。 我也尝试在用户名前面加上 ownme\username 我对 AD 非常陌生,所以问题可能很简单。

    Domain = domain;
    _entry = new DirectoryEntry("LDAP://DC1/DC=ownme,DC=local", username, password, AuthenticationTypes.ServerBind);
    _directorySearcher = new DirectorySearcher(_entry, "(objectClass=*)", new string[] {"namingContexts"}, SearchScope.Subtree);
    var namingContext = _directorySearcher.FindOne();

【问题讨论】:

  • 这应该能够使用您的用户名/密码进行连接,否则您需要先检查您是否通过 LDAP/AD 对该域具有权限
  • 我没有对 \ 进行双重转义,并且绝对需要域名前缀。
  • 你有没有想过使用 PrincipalContext 例如 using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "YOURDOMAIN")) { // 验证凭证 bool isValid = pc.ValidateCredentials("myuser", “我的密码”)}
  • 哦,那就更好了。
  • 然后pc context 在这种情况下,您可以看到您需要的所有属性.. 电子邮件地址、用户名等.. 如果用户在 AD 中,那么如果不是这样,您将获得结果一个死的放弃......

标签: c# active-directory ldap directoryservices


【解决方案1】:

问题出在凭据上。您需要在用户名中指定域前缀或查看我的问题中的其中一个 cmets。 我有 var username = "domain\username"; 我应该写 var username = @"domain\username";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 2020-11-22
    • 1970-01-01
    相关资源
    最近更新 更多