我正在使用DirectorySearcher類來查詢活動目錄。它在單個頁面中提供所有記錄(超過5000個)。我想每頁獲得100條記錄。所以我轉到了SearchRequest類。使用SearchRequest類,每頁可以獲得100條記錄。但對於特定的查詢,它不起作用。我想讓所有的用戶使用他們的「samaccountname或顯示名稱以'a'開頭」「正常工作。然後,我想讓所有用戶使用他們的「samaccountname和顯示名稱以'a'開頭」,這是行不通的。我可以猜出原因,其中一些用戶在沒有任何顯示名稱的情況下啓動他們的samaccountname。有關此問題的任何解決方法?請指引我System.DirectoryServices.Protocols.SearchRequest Ldap查詢執行問題
請參考Active Directory中的下列代碼
//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 17:06:08