我正在使用DirectorySearcher类来查询活动目录。它将所有记录放在一个页面中(超过5000条)。我希望每页有100条记录。所以我转到了SearchRequest班。使用SearchRequest类,我可以获得每页100条记录。但是对于特定的查询,它不起作用。我想让所有用户的"samaccountname或displayname以‘a’开头“都能正常工作。然后我想获取所有用户的"samaccountname和displayname以‘a’开头“,这是不起作用的。我可以猜到原因,一些用户在他们的samaccountname开头没有任何displayname。是否有解决此问题的方法?请给我指引
请参考以下代码
//This query works fine
//string filter = "(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(|(samaccountname=a*)(displayname=a*)))";
/* Not works */
string filter = "(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(&(samaccountname=a*)(displayname=a*)))";
LdapConnection connection = new LdapConnection(serverName);
string[] attribs = { "samaccountname", "displayname" };
// create a SearchRequest object
SearchRequest searchRequest = new SearchRequest
(scope,
filter,
System.DirectoryServices.Protocols.SearchScope.Subtree,
attribs);
SortRequestControl sortRequest = new SortRequestControl("samaccountname", false);
searchRequest.Controls.Add(sortRequest);
VlvRequestControl vlvRequest =
new VlvRequestControl(0, numEntries, offsetVal);
searchRequest.Controls.Add(vlvRequest);
SearchResponse searchResponse =
(SearchResponse)connection.SendRequest(searchRequest);
if (searchResponse.Controls.Length != 2 ||
!(searchResponse.Controls[0] is SortResponseControl))
{
Console.WriteLine("The server does not support VLV");
return null;
}发布于 2012-02-10 10:33:47
您确实想在Active Directory中使用displayName吗?也许fullName或CN会是更准确的选择。
https://stackoverflow.com/questions/9207170
复制相似问题