使用DirectorySearcher或SearchRequest时缺少Active Directory组

时间:2016-12-01 09:12:49

标签: c# active-directory ldap

我想列出域中的所有组。如果我使用DirectorySearcher或LdapConnection和SearchRequest对象,则返回的列表中缺少某些组。但是如果我从DirectoryEntry类遍历目录的根目录遍历所有树,我就可以获得组。

我使用AD Explorer工具检查了返回组和缺失组的属性,但我看不出它们之间有任何区别。我需要使用LdapConnection + SearchRequest,因为如果我需要使用LDAP + SSL,DirectoryEntry不允许我管理证书问题。

有没有人有同样的问题?可能有什么问题?

搜索操作的示例代码;

LdapConnection _connection = new LdapConnection(new LdapDirectoryIdentifier("MTS", 389));
_connection.AuthType = AuthType.Basic;
_connection.Credential = new NetworkCredential("MTS\user1", "test123");

string _target = "dc=MTS,dc=com";

SearchRequest _request = new SearchRequest(_target, "(&(objectCategory=Group)(objectClass=group))", System.DirectoryServices.Protocols.SearchScope.Subtree, new string[] { "sAMAccountName" });

var _response = (SearchResponse)_connection.SendRequest(_request);

List<string> _namelist = new List<string>(16);

foreach (SearchResultEntry entry in _response.Entries)
{
      if (entry.Attributes["sAMAccountName"].Count > 0)
        _namelist.Add(entry.Attributes["sAMAccountName"][0].ToString());
}

修改1

如果我更改搜索过滤器并仅搜索缺失的组,则会找到该组。在搜索过滤器工作并获取组后,

"(&(sAMAccountName=testGroup)(objectCategory=Group)(objectClass=group))"

可能存在限制,但我将Sizelimit和TimeLimit设置得如此之高,搜索永远不会返回任何限制的错误。

1 个答案:

答案 0 :(得分:0)

我有同样的问题,没有超时或错误但结果不完整。 我将尝试PageResultRequestControl,谢谢。

相关问题