英文:
.NET core 3.1 novell.directory.ldap doesn't get all LDAP users
问题
我正在开发一个基于.NET Core (3.1)的应用程序,它连接到Active Directory以获取用户信息。
我使用的是Novell.Directory.Ldap.NETStandard 3.6.0版本。
我有超过4000个用户,但我只得到了大约800个用户。
LDAP MaxPageSize是5000,当我尝试使用System.DirectoryServices时,我可以获取所有用户。
但我必须使用Novell,因为我需要将应用程序部署在docker上。
```lang-cs
var ldapConn = new LdapConnection { SecureSocketLayer = false };
ldapConn.Connect(domainName, 389);
ldapConn.Bind(username, password);
ILdapSearchResults lsc = ldapConn.Search("OU=myOU,DC=domain,DC=com",
LdapConnection.ScopeSub, "(objectClass=person)", null, false);
CSV WriteToCSV = new CSV();
while (lsc.HasMore())
{
nextEntry = lsc.Next();
LdapAttributeSet attributeSet = nextEntry.GetAttributeSet();
if (attributeSet.ContainsKey("sAMAccountName"))
{
string result = attributeSet.GetAttribute("sAMAccountName").StringValue;
WriteToCSV.WriteToCsv("Persons.csv",);
}
}
> 错误: 超过大小限制
英文:
I am developing an application based on .NET Core (3.1) which is connect to Active Directory to get the users.
I use Novell.Directory.Ldap.NETStandard 3.6.0.
I have more than 4000 users but I got just about 800 users.
LDAP MaxPageSize is 5000, and when I try using System.DirectoryServices I got all users.
but I have to use Novell because I need to publish the application on docker.
var ldapConn = new LdapConnection { SecureSocketLayer = false };
ldapConn.Connect(domainName, 389);
ldapConn.Bind(username, password);
ILdapSearchResults lsc = ldapConn.Search("OU=myOU,DC=domain,DC=com",
LdapConnection.ScopeSub, "(objectClass=person)", null, false);
CSV WriteToCSV = new CSV();
while (lsc.HasMore())
{
nextEntry = lsc.Next();
LdapAttributeSet attributeSet = nextEntry.GetAttributeSet();
if (attributeSet.ContainsKey("sAMAccountName"))
{
string result = attributeSet.GetAttribute("sAMAccountName").StringValue;
WriteToCSV.WriteToCsv("Persons.csv",);
}
}
> Error: Size Limit Exceeded
答案1
得分: 1
我使用"SearchUsingSimplePaging"函数来解决这个问题
var ldapConn = new LdapConnection { SecureSocketLayer = false };
ldapConn.Connect(domainName, 389);
ldapConn.Bind(username, password);
SearchOptions options = new SearchOptions("OU=my_OU,DC=domain,DC=com", LdapConnection.ScopeSub, "(objectClass=person)", null);
var searchResult = ldapConn.SearchUsingSimplePaging(options, 1000);
CSV WriteToCSV = new CSV();
foreach (var ldapEntry in searchResult)
{
dapAttributeSet attributeSet = ldapEntry.GetAttributeSet();
if (attributeSet.ContainsKey("sAMAccountName"))
{
string result = attributeSet.GetAttribute("sAMAccountName").StringValue;
WriteToCSV.WriteToCsv("Persons.csv", result);
}
}
英文:
I solve the problem by using "SearchUsingSimplePaging" function
var ldapConn = new LdapConnection {SecureSocketLayer = false };
ldapConn.Connect(domainName, 389);
ldapConn.Bind(username, password);
SearchOptions options=new SearchOptions("OU=my_OU,DC=domain,DC=com",LdapConnection.ScopeSub,"(objectClass=person)",null);
var searchResult=ldapConn.SearchUsingSimplePaging(options, 1000);
CSV WriteToCSV = new CSV();
foreach (var ldapEntry in searchResult)
{
dapAttributeSet attributeSet = ldapEntry.GetAttributeSet();
if (attributeSet.ContainsKey("sAMAccountName"))
{
string result = attributeSet.GetAttribute("sAMAccountName").StringValue;
WriteToCSV.WriteToCsv("Persons.csv", result);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论