使用C#连接到OpenLDAP服务器

时间:2019-11-15 10:09:58

标签: c# ldap openldap

我在CentOS7上设置了OpenLDAP服务器,我试图连接到该LDAP服务器并在其上进行搜索。简单的C#程序。这适用于Active Directory,但是我无法在OpenLDAP上搜索。

  txtUsername.Text = "cn=ldapadm,dc=field,dc=linuxhostsupport,dc=com";
  txtPassword.Text = "password";
  txtLDAPPort.Text = "389";
  txtBaseDN.Text = "dc=linuxhostsupport,dc=com";

  string DomainPath = String.Format("LDAP://{0}:{1}/{2}", txtLDAPServer.Text, txtLDAPPort.Text, txtBaseDN.Text);
  DirectoryEntry searchRoot = new DirectoryEntry(DomainPath, txtUsername.Text, txtPassword.Text);
  DirectorySearcher search = new DirectorySearcher(searchRoot);
  search.Filter = "(objectClass=*)";
  search.PropertiesToLoad.Add("displayname");
  SearchResult result;
  SearchResultCollection resultCol = search.FindAll();

我要例外-

  An invalid dn syntax has been specified.

  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  at System.DirectoryServices.DirectoryEntry.Bind()
  at System.DirectoryServices.DirectoryEntry.get_AdsObject()
  at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
  at System.DirectoryServices.DirectorySearcher.FindAll()
  at LDAPSearchTest.Form1.btnSearch_Click(Object sender, EventArgs e)

我在这里想念什么?

我已推荐https://linuxhostsupport.com/blog/how-to-install-ldap-on-centos-7/来设置OpenLDAP。

问候 尼罗什

0 个答案:

没有答案
相关问题