简体   繁体   English

尝试连接时出现LDAP C#错误

[英]LDAP C# error when trying to connect

I keep getting the following error when trying to connect to an LDAP server. 尝试连接到LDAP服务器时,我始终收到以下错误。 The user name or password is incorrect. 用户名或密码不正确。 It occurs on the .FindOne() If I use AuthenticationTypes.Encryption i get an error: The server is not operational. 如果我使用AuthenticationTypes.Encryption,它会在.FindOne()上发生错误:服务器无法运行。 I've also tried to prepend the username with ownme\\username I'm extremely newbish with AD so the issue might be so simple. 我还尝试在用户名前加上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();

The problem was credentials. 问题是凭证。 You need to specify the domain prefix in the username or look at one of the comments in my question. 您需要在用户名中指定域前缀,或查看我的问题中的评论之一。 I had var username = "domain\\username"; 我有var username =“ domain \\ username”; I should have written var username = @"domain\\username"; 我应该写var username = @“ domain \\ username”;

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

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