使用C#查询LDAP以获取组成员资格 [英] Using C# to query LDAP for group membership

查看:81
本文介绍了使用C#查询LDAP以获取组成员资格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我希望有人可以提供帮助,我已经编写了一个简单的程序来查询群组成员资格。代码工作并向我显示AD组,但不显示我在LDAP中显示的组成员资格。 

Hi All, im hoping someone can help, i have manged to code a simple programme to query group membership. The code works and shows me AD groups however does not show me group membership which is shown in LDAP. 

我的代码如下,希望有人可以帮助我

My code is below, hoping someone can help me

提前致谢

    class Program
    {
        static void Main(string[] args)
        {

            UserPrincipal user = null;
           
            string userName = "xxxxxxx";
    //        Console.WriteLine("userName");
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domian address", "DC=xxx,DC=xxxxx,DC=xxxx,DC=xxxx");           
            {
                    if ((user = UserPrincipal.FindByIdentity(ctx, userName)) != null)
                    {
                        PrincipalSearchResult<Principal> groups = user.GetGroups();
                        foreach (GroupPrincipal g in groups)
                        {
                            Console.WriteLine(g.Name);
                        }
                    }
             }
            Console.ReadLine();
        }
    }
}







推荐答案

您正在使用
GetGroups
。它很微妙,但文档指定这只返回直接成员资格。使用

GetAuthorizationGroups
获取所有组成员资格。
You're using GetGroups. It's subtle but the documentation specifies that this returns only direct membership. Use GetAuthorizationGroups to get all the group memberships.


这篇关于使用C#查询LDAP以获取组成员资格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆