C#的Active Directory服务的findAll()只返回1000个条目 [英] c# Active Directory Services findAll() returns only 1000 entries

查看:229
本文介绍了C#的Active Directory服务的findAll()只返回1000个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  <一href="http://stackoverflow.com/questions/90652/can-i-get-more-than-1000-records-from-a-directorysearcher-in-asp-net">Can我得到超过1000条记录,从Asp.Net一个DirectorySearcher从?

我在寻找使用ADS目录搜索的findAll()方法现存登录(如下面的code)。它出现的findAll方法只返回1000个条目虽然有比这更条目。 怎样的FindAll每次登录的()?

 的IList&LT;字符串&GT; adslist =新的名单,其中,串&GT;();
    使用(的DirectoryEntry德=新的DirectoryEntry(LDAP://armlink.com,NULL,NULL,AuthenticationTypes.Secure))
    使用(DirectorySearcher从DS =新DirectorySearcher从(德(对象类=用户),新的String [] {SAM帐户}))

        的foreach(在ds.FindAll信息搜索结果SR())
        {
            字符串[] E = sr.Path.Split(新的String [] {LDAP://,OU =,,,DC =,.COM,/ CN =},StringSplitOptions .RemoveEmptyEntries);
            ResultPropertyCollection PC = sr.Properties;
            adslist.Add(E [0] +/+ PC [SAM帐户名] [0]的ToString());
            //的Debug.WriteLine(adslist.Last());
        }
 

解决方案

这是由于服务器端的限制。从 DirectorySearcher.SizeLimit 文件:

  

对象的最大数量   服务器返回一个搜索。该   默认值是零,这意味着对   使用服务器确定默认尺寸   限制的1000个条目。

  

如果您设置为的sizeLimit值比1000服务器确定的默认较大   条目,服务器将确定使用默认值。

基本上从这个,它看起来像除非有更改服务器端默认的方式,你将被限制在1000个条目。这有可能是指定一个每页会让你获取一定数量的时间,用的的大于1000 ...不知道。

顺便说一句,它看起来像你应该也有周围的 SearchResultCollection A 使用指令:

 使用(SearchResultCollection结果= ds.FindAll())
{
    的foreach(在结果信息搜索结果SR)
    {
        ...
    }
}
 

Possible Duplicate:
Can I get more than 1000 records from a DirectorySearcher in Asp.Net?

I am searching for existing logins using ADS Directory searcher findAll() method (as in following code). It appears the findall method returns only 1000 entries although there are more entries than that. How do I findAll() of every login ?

    IList<string> adslist = new List<string>();
    using (DirectoryEntry de = new DirectoryEntry("LDAP://armlink.com", null, null, AuthenticationTypes.Secure))
    using (DirectorySearcher ds = new DirectorySearcher(de, "(objectclass=user)", new string[] { "samaccountname" }))

        foreach (SearchResult sr in ds.FindAll())
        {
            string[] e = sr.Path.Split(new string[] { "LDAP://", "OU=", ",", "DC=", ".com", "/CN=" }, StringSplitOptions.RemoveEmptyEntries);
            ResultPropertyCollection pc = sr.Properties;
            adslist.Add(e[0] + "/" + pc["samaccountname"][0].ToString());
            //   Debug.WriteLine(adslist.Last());
        }

解决方案

This is due to a server-side limit. From the DirectorySearcher.SizeLimit documentation:

The maximum number of objects that the server returns in a search. The default value is zero, which means to use the server-determined default size limit of 1000 entries.

And:

If you set SizeLimit to a value that is larger than the server-determined default of 1000 entries, the server-determined default is used.

Basically from this, it looks like unless there's a way of changing the server-side default, you're going to be limited to 1000 entries. It's possible that specifying a PageSize will let you fetch a certain number at a time, with a total greater than 1000... not sure.

By the way, it looks like you should also have a using directive around the SearchResultCollection:

using (SearchResultCollection results = ds.FindAll())
{
    foreach (SearchResult sr in results) 
    {
        ...
    }
}

这篇关于C#的Active Directory服务的findAll()只返回1000个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆