.NET Core - Novell LDAPAD - 搜索一个用户所属的组 - 有谁做过?

问题描述 投票:0回答:1

我的代码在搜索用户的组时运行良好,但问题是它只返回一个组。我的目标是得到该用户所属的所有组。我怎样才能解决这个问题?任何帮助都将是非常感激的。

LdapSearchResults lsc = (LdapSearchResults)ldapCon.Search(                    
    "DC=adl,DC=local",                   
    LdapConnection.ScopeSub,                    
    "(sAMAccountName=" + Username + ")",
    null,
    false
);

while (lsc.HasMore())
{                        
    try
    {
        var nextEntry = lsc.Next();                            
        nextEntry.GetAttributeSet();                           

        adGroups.Add(new ADUserSecurityGroupModel { 
            member = nextEntry.GetAttribute("memberOf").StringValue,
            distinguishedName = nextEntry.GetAttribute("sAMAccountName").StringValue 
        });
    }
    catch (LdapException ex)
    {
        Console.WriteLine("Error: " + ex.ToString());
        continue;
    }
}
c# .net-core ldap-query
1个回答
0
投票

经过一番研究和学习,终于我自己有了一个解决方法,关于这里发布的问题。这个变通方法足以满足要求。

LdapSearchResults lsc = (LdapSearchResults)ldapCon.Search(
OU=Dashboards,DC=adl,DC=local",
LdapConnection.ScopeSub,
"(&(objectClass=group)(member:1.2.840.113556.1.4.1941:=CN=" + UserFullName + 
",OU=Company Name,DC=adl,DC=local))",
null,
false);                

while (lsc.HasMore())  
 {
  LdapEntry nextEntry = null;
  try
    {
      nextEntry = lsc.Next();
    }
  catch
    {                            
      continue;
    }
  nextEntry.GetAttributeSet();
  adGroups.Add(new ADUserSecurityGroupModel { cn = 
  nextEntry.GetAttribute("cn").StringValue });
 };
© www.soinside.com 2019 - 2024. All rights reserved.