.net ldap身份验证的dn语法错误

.net ldap身份验证的dn语法错误,.net,authentication,ldap,dn,.net,Authentication,Ldap,Dn,我很难编写一个可以执行LDAP身份验证的模块 当我在浏览器中输入以下行并按enter键时,Windows联系人应用程序将显示来自服务器的记录,以便我知道这是要连接到的正确位置: ldap://directory.abc.edu/uid=asmith,ou=People,o=abc.edu 但是,当我想在代码中使用相同的东西时,我会得到一条“无效dn语法”错误消息 这是我的密码: public void LDAPResult() { u

我很难编写一个可以执行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);
                }
            }            
        }
非常感谢您的帮助。
谢谢,

你应该看看这里

这里呢


特别是对于“new DirectoryEntry(…)”用法:)

我不确定您要连接到哪个LDAP目录,但您的DN看起来不太正确


尤其是“o=abc.edu”部分。在Active Directory(我最熟悉的目录)中,DN最终将是uid=asmith,ou=People,dc=abc,dc=edu。请注意,abc和edu是明显不同的部分。由于您使用的是O而不是DC,我猜目录不是AD,但是域名的部分可能仍然使用两个O来表示。o=abc,o=edu也许?

非常正确。阿米尔,你真的在“o=”level object的RDN中加了一个点吗?嗯,这是一个很好的观点。我修复了这个错误,仍然得到相同的错误,“dn syntax error”,但后来我将其更改为以下格式,错误消息也更改了。我现在使用的格式是:使用(DirectoryEntry root=newdirectoryEntry(string.format(@“LDAP://CN=directory.gmu.edu,OU=People,DC=gmu,DC=edu”))现在当我运行程序时,需要一段时间,然后它会说“从服务器返回了一个引用”,有人能告诉我这意味着什么以及我现在应该做什么吗?非常感谢您的帮助John。根据DirectorySearching类的文档,您传递给搜索者的目录条目是搜索的根目录。所以您可能只想传递“LDAP://OU=People,DC=gmu,DC=edu”。不过,人可能是一个容器而不是OU,所以您可能还希望尝试“LDAP://CN=People,DC=gmu,DC=edu”。如果您正在搜索AD域控制器,则用户的默认位置实际上是CN=users,因此您也可以尝试“LDAP://CN=users,dc=gmu,dc=edu”。John,感谢您的帮助。对于所有这些,我仍然会收到“从服务器返回的推荐”。您知道我至少可以检查一下是否可以连接到LDAP服务器的方法吗?或者得到一个一般的回复,比如所有东西的列表或者目录结构的列表?问题是,当我在浏览器中放入以下行时,我会取回记录!ldap://directory.abc.edu/uid=asmith,ou=People,o=abc.edu我还有一个与LDAP服务器正确通信的PHP应用程序,但我不能在C#中做同样的事情。这告诉你什么?再次感谢!