简体   繁体   English

LDAP,DirectoryServices c#搜索查询基础

[英]LDAP, DirectoryServices c# search base for queries

I'm trying to use an LDAP server that has the client login that apparently has to be a simple bind (with a Distinguished Name). 我正在尝试使用具有客户端登录名(显然必须是简单绑定)(具有专有名称)的LDAP服务器。

var clientEntry = new DirectoryEntry(
"LDAP://server.de",
"cn=medialibrary, ou=special users, dc=uni, dc=de",
"password",
AuthenticationTypes.None);

DirectorySearcher directorySearch = new DirectorySearcher(clientEntry, "(cn=searchuser");

SearchResult result = directorySearch.FindOne();

The connection via DN works fine. 通过DN的连接工作正常。 However the search for cn=searchuser returns no users (and no errors). 但是,搜索cn = searchuser不会返回任何用户(也没有错误)。

The user we are trying to search for is in path: 我们尝试搜索的用户位于以下路径:

ou=people,dc=uni,dc=de OU =人,DC =单,DC = DE

In the LDAP-Admin utility we can log in using the cn=medialibrary etc DN and if we then modify the search base to "ou=people,dc=uni-potsdam,dc=de" and then do the search we find the cn=searchuser entry 在LDAP-Admin实用程序中,我们可以使用cn = medialibrary etc DN登录,然后如果将搜索基础修改为“ ou = people,dc = uni-potsdam,dc = de”,然后进行搜索,则会找到cn = searchuser条目

The question is what is the equivilent to modifying the search base we can do in that utility in C# code? 问题是,用C#代码在该实用程序中修改搜索库的等效性是什么?

(The target user is in a different branch to the default branch given by the directory entry I must originally bind to.) (目标用户与我最初必须绑定到的目录条目所给定的默认分支位于不同的分支中。)

I believe this original Directory url has been tried and did not work (permissions?) 我相信这个原始的目录url已经尝试过并且没有用(权限?)

LDAP://server.de/ou=people,dc=uni,dc=de LDAP://server.de/ou=people,dc=uni,dc=de

string LDAPpAth = "dc=uni,dc=de"
string filter = "(cn=searchuser)"
string username = "medialibrary"
string password = "password"
DirectoryEntry startingPoint = new DirectoryEntry("LDAP://"+LDAPpAth, username, password);
DirectorySearcher searcher = new DirectorySearcher(startingPoint);
searcher.Filter = filter;

from there you can do the searcher.findone and use the value for what you need. 从那里,您可以执行searcher.findone并使用所需的值。 let me know if that works. 让我知道是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM