gpt4 book ai didi

c# - 按日期时间对 DirectorySearcher 查询的结果进行排序

转载 作者:行者123 更新时间:2023-11-30 18:00:23 24 4
gpt4 key购买 nike

我有以下代码:

// Declare new DirectoryEntry and DirectorySearcher
DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);

// Set the properties of the DirectorySearcher
dsSearch.Filter = "(objectClass=Computer)";
dsSearch.PropertiesToLoad.Add("whenCreated");
dsSearch.PropertiesToLoad.Add("description");
dsSearch.PropertiesToLoad.Add("operatingSystem");
dsSearch.PropertiesToLoad.Add("name");

// Execute the search
SearchResultCollection computersFound = dsSearch.FindAll();

我想按 whenCreated 属性对结果进行降序排序,以便最新的计算机对象位于顶部。

我不能简单地做:

SortOption sortedResults = new SortOption("whenCreated", SortDirection.Descending);
dsSearch.Sort = sortedResults;

因为服务器返回错误(http://social.technet.microsoft.com/Forums/en-US/winserverDS/thread/183a8f2c-0cf7-4081-9110-4cf41b91dcbf/)

最好的排序方式是什么?

最佳答案

您可以按照 MSDN here 中的说明在服务器端执行此操作:

      new DirectorySearcher(entry)
{
Sort = new SortOption("cn", SortDirection.Ascending),
PropertiesToLoad = {"cn"}
};

链接的问题线程已解决:

We have the same issue on AD Windows 2008 R2

  • applied kb977180-v2 http://support.microsoft.com/kb/977180
  • and added keyHKLM\System\CurrentControlSet\Services\NTDS\Parameters
  • Add String value “DSA Heuristics”
  • Set the value to 000000000001
  • restart
  • after this issue solved

关于c# - 按日期时间对 DirectorySearcher 查询的结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10158275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com