编辑:IMO,这应该发布在Serverfault中,所以我created one并投票决定在Stackoverflow中关闭它。
我尝试搜索并使用命令行来测试与LDAP服务器的连接,但是即使在我的本地计算机上,它也会引发错误“无法连接到LDAP服务器”
我使用Visual Studio在本地计算机上调试代码并成功连接吗?
所以how to connect to LDAP serrver using cmd for windows 10?
Cmd错误:
ldapsearch -x -h LDAP://adserverxx.xx -p 389 -D "cn=ldap,dc=test" -w passxx "objectclass=*"
代码C#run ok and successfully authenticated(ASP.NET)
bool bSucceeded;
string strAccountId = "ldap";
string strAccountPas = "inxxx";
string strError = "";
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://serveraddxx:389", strAccountId, strAccountPas);
using (DirectorySearcher adsSearcher = new DirectorySearcher(directoryEntry))
{
//adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
adsSearcher.Filter = "(sAMAccountName=" + strAccountId + ")";
try
{
SearchResult adsSearchResult = adsSearcher.FindOne();
bSucceeded = true;
string strAuthenticatedBy = "Active Directory";
strError = "User has been authenticated by Active Directory.";
}
catch (Exception ex)
{
// Failed to authenticate. Most likely it is caused by unknown user
// id or bad strPassword.
strError = ex.ToString();
}
finally
{
directoryEntry.Close();
}
}
P / S:我们今天(昨天可以)从托管服务器(Web应用程序)连接到ldap时遇到问题,它仅引发异常“找不到网络路径”。