我尝试搜索并使用命令行来测试与 LDAP 服务器的连接,但即使在我的本地计算机上也会出现错误“无法连接到 LDAP 服务器”
我使用 Visual Studio 在本地计算机上调试代码并且连接成功?
那么如何使用 Windows 10 的 cmd 连接到 LDAP 服务器?
命令错误:
ldapsearch -x -h LDAP://adserverxx.xx -p 389 -D "cn=ldap,dc=test" -w passxx "objectclass=*"
代码 C#运行正常并且验证成功通过使用 Visual Studio,在我的本地计算机上运行(错误在托管服务器中未找到网络路径)(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 时遇到了问题(昨天没有问题),它只抛出异常“未找到网络路径”。