c# Active Directory 服务 findAll() 仅返回 1000 个条目
- 作者: 灵囧境
- 来源: 51数据库
- 2022-10-21
问题描述
可能的重复:
我可以得到超过 1000来自 Asp.Net 中 DirectorySearcher 的记录?
我正在使用 ADS 目录搜索器 findAll() 方法搜索现有登录名(如下面的代码所示).看起来 findall 方法只返回 1000 个条目,尽管条目多于此.我如何找到每次登录的所有()?
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());
}
推荐答案
这是由于服务器端限制造成的.来自 DirectorySearcher.SizeLimit 文档:
This is due to a server-side limit. From the DirectorySearcher.SizeLimit documentation:
对象的最大数量服务器在搜索中返回.这默认值为零,这意味着使用服务器确定的默认大小限制为 1000 个条目.
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.
还有:
如果您将 SizeLimit 设置为大于服务器确定的默认值 1000条目,使用服务器确定的默认值.
If you set SizeLimit to a value that is larger than the server-determined default of 1000 entries, the server-determined default is used.
基本上,除非有一种方法可以更改服务器端默认值,否则您将被限制为 1000 个条目.指定 PageSize 可能会让您一次获取某个数字,total 大于 1000 ......不确定.
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.
顺便说一句,您似乎还应该在 SearchResultCollection 周围有一个 using 指令:
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#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
