System.DirectoryServices.Protocols.SearchRequest Ldap 查询执行问题
我正在使用 DirectorySearcher 类来查询活动目录。它在一个页面中提供了所有记录(超过 5000 条)。我想每页获取 100 条记录。所以我转向 SearchRequest 类。使用 SearchRequest 类,我每页可以获得 100 条记录。但对于特定查询它不起作用。我想让所有用户的“samaccountname 或显示名称以 'a' 开头”工作正常。然后我想让所有用户的“samaccountname 和显示名称以 'a' 开头”,这是行不通的。我可以猜到原因,一些用户以没有任何显示名称的方式启动他们的 samaccountname。这个问题有什么解决方法吗?请指导我
请参考以下代码
//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;
}
I am using DirectorySearcher class to query the active directory. It gives all the records in a single page (more than 5000). I want to get 100 records per page. So I moved to SearchRequest class. Using SearchRequest class I can get 100 records per page. But for particular query it is not working. I want to get all the users with their "samaccountname or displayname starts with 'a'" works fine. Then I want to get all the users with their "samaccountname and displayname starts with 'a'", this it is not working. I can guess the reason, some of the users starts their samaccountname with a not having any displayname. Any workaround for this issue? Please guide me
Please refer the following code
//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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实希望在 Active Directory 中显示名称吗?也许 fullName 或 CN 是更准确的选择。
Do you really want displayName in Active Directory? Perhaps fullName or CN would be a more accurate choice.