我在编写可以执行 LDAP 身份验证的模块时遇到困难。
当我在浏览器中输入以下行并按 Enter 键时,Windows 联系人应用程序将向我显示来自服务器的记录,因此我知道这是连接到的正确位置:
ldap://directory.abc.edu/uid=asmith,ou=People,o=abc.edu
但是当我想在代码中使用相同的东西时,我收到“无效的 dn 语法”错误消息。
这是我的代码:
public void LDAPResult()
{
using (DirectoryEntry root = new DirectoryEntry(string.Format(@"LDAP://directory.abc.edu/uid=asmith,ou=People,o=abc.edu")))
{
using (DirectorySearcher searcher = new DirectorySearcher(root))
{
//This following line give me the error
**SearchResultCollection results = searcher.FindAll();**
//The rest is not actually important, I never get there to see if it works properly.
StringBuilder summary = new StringBuilder();
foreach (SearchResult result in results)
{
foreach (string propName in result.Properties.PropertyNames)
{
foreach (string s in result.Properties[propName])
{
summary.Append(" " + propName + ": " + s + "\r\n");
}
}
summary.Append("\r\n");
}
Console.WriteLine(summary);
}
}
}
对此的任何帮助都非常感谢。谢谢,