.NET Core 3.1的novell.directory.ldap无法获取所有LDAP用户。

huangapple go评论95阅读模式
英文:

.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上。

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", result);
    }
}                

> 错误:超过大小限制

英文:

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);
             }
         }

huangapple
  • 本文由 发表于 2023年8月9日 16:04:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定