简体   繁体   English

.NET 核心 - Novell LDAP/AD - 组搜索他所属的用户 - 有人让它工作吗?

[英].NET Core - Novell LDAP/AD - Group search for a user that he belongs to - Has anybody made it work?

My code given below is working well while searching groups for a user, but the problem is it returns only one group.下面给出的代码在为用户搜索组时运行良好,但问题是它只返回一个组。 My goal is to get all groups the user belongs to.我的目标是获取用户所属的所有组。 How can I get rid of this problem?我怎样才能摆脱这个问题? Any help will be much appreciated.任何帮助都感激不尽。

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

After some research and study finally I have got a solution regarding the problem posted here.经过一番研究和研究,我终于找到了关于这里发布的问题的解决方案。 This workaround is enough to meet the requirement.此解决方法足以满足要求。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Novell LDAP C# - Novell.Directory.Ldap - 有没有人让它工作? - Novell LDAP C# - Novell.Directory.Ldap - Has anybody made it work? 使用Novell LDAP对.NET Core中的AD进行页面LDAP查询 - Page LDAP query against AD in .NET Core using Novell LDAP 检查用户是否属于 AD 组 .net core - Check if user belongs to an AD group .net core 是否可以使用 Novell 软件包找到 LDAP 用户所属的组? (C#) - Is it possible to find the group(s) that an LDAP user belongs to using the Novell package? (C#) 使用 Novell.Directory.Ldap.NETStandard 在 LDAP 中获取用户组 - Getting user group in LDAP using Novell.Directory.Ldap.NETStandard 如何检查用户是否属于某个广告组? - How to check if a user belongs to an AD group? 更改密码对Asp.Net Core 2的Novell LDAP修改不生效 - Change Password not taking effect with Novell LDAP Modification for Asp.Net Core 2 枚举ASP.Net 5 / core中用户的AD安全组成员身份? - Enumerating AD Security Group memberships for a User in ASP.Net 5/core? 使用 .NET Core 5 和 Novell.Directory.Ldap.NETStandard 从 Domino LDAP 服务器获取 1000 多行 - Fetching more than 1000 rows from Domino LDAP server using .NET Core 5 and Novell.Directory.Ldap.NETStandard 如果用户未登录.NET Core,如何重定向用户? - How to redirect user if he is not logged in .NET Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM