我需要读取广告中的所有用户。下面是我使用的代码:
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Controls;
using System.Linq;
namespace LdapTestApp
{
class Program
{
static void Main()
{
LdapConnection ldapConn = new LdapConnection();
ldapConn.SecureSocketLayer = true;
ldapConn.Connect(HOST, PORT);
try
{
var cntRead = 0;
int? cntTotal = null;
var curPage = 0;
ldapConn.Bind(USERNAME, PASSWORD);
do
{
var constraints = new LdapSearchConstraints();
constraints.SetControls(new LdapControl[]
{
new LdapSortControl(new LdapSortKey("sn"), true),
new LdapVirtualListControl("sn=*", 0, 10)
});
ILdapSearchResults searchResults = ldapConn.Search(
"OU=All Users,DC=homecredit,DC=ru",
LdapConnection.ScopeSub,
"(&(objectCategory=person)(objectClass=user))",
null,
false,
constraints
);
while (searchResults.HasMore() && ((cntTotal == null) || (cntRead < cntTotal)))
{
++cntRead;
try
{
LdapEntry entry = searchResults.Next();
}
catch (LdapReferralException)
{
continue;
}
}
++curPage;
cntTotal = GetTotalCount(searchResults as LdapSearchResults);
} while ((cntTotal != null) && (cntRead < cntTotal));
}
finally
{
ldapConn.Disconnect();
}
}
private static int? GetTotalCount(LdapSearchResults results)
{
if (results.ResponseControls != null)
{
var r = (from c in results.ResponseControls
let d = c as LdapVirtualListResponse
where (d != null)
select (LdapVirtualListResponse)c).SingleOrDefault();
if (r != null)
{
return r.ContentCount;
}
}
return null;
}
}
}
我使用这个问题Page LDAP query against AD in .NET Core using Novell LDAP作为基础。不幸的是,当我试图接收第一个条目时,我得到了这个异常:
"Unavailable Critical Extension"
000020EF: SvcErr: DSID-03140594, problem 5010 (UNAVAIL_EXTENSION), data 0
我做错了什么?
发布于 2020-11-19 21:23:07
VLV是浏览索引,与是否浏览大量条目没有直接关系(参见generic documentation)。因此,即使这个控件在你的AD上被激活,你也不能以这种方式检索超过1000个元素:
在AD上,
MaxPageSize
默认为1000 (请参阅documentation)所以你能做的是:
Novell
答案是LDAP no:审查您的设计,在您的LDAP搜索过滤器、搜索库等方面更加具体。
答案是yes
MaxPageSize
值,但此设置是全局的,可能会导致几个副作用(例如,如果每个人都开始不断地请求所有用户,会发生什么呢?)MaxPageSize
、超时等)发布于 2020-11-27 19:18:10
我不得不使用这里描述的方法:https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard/issues/71#issuecomment-420917269
解决方案远非完美,但至少我能够继续前进。
发布于 2020-12-29 04:07:53
从3.5版本开始,该库支持简单的分页结果控件- https://ldapwiki.com/wiki/Simple%20Paged%20Results%20Control -并且使用方法就像ldapConnection.SearchUsingSimplePaging(searchOptions,searchOptions或Github searchOptions,pageSize一样简单)-有关更多详细信息,请参阅Github repo - https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard,更具体地说,使用测试作为使用示例。
https://stackoverflow.com/questions/64909026
复制相似问题