GroupPrincipal.IsMemberOf始终返回false [英] GroupPrincipal.IsMemberOf always returns false

查看:178
本文介绍了GroupPrincipal.IsMemberOf始终返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,它检查一组是一组的成员。我有功能的2个版本,既没有按预期方式工作:

I have a function that checks if a group is a member of a group. I have 2 variations of the function, neither work as expected:

public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp)
        {
            return gp.IsMemberOf(pgp); 
        }

 public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp)
        {
            if (gp != null && pgp != null)
            {
                return pgp.Members.Contains(gp);
            }
            else
            {
                return false;
            }
        }

这两种看好,但总是返回false。当谈到时间来调用GroupPrincipal.save方法,对象已经存在,则会引发错误。

Both look promising, however always return false. When it comes time to call the GroupPrincipal.save method, an object already exists error is thrown.

我跑了foreach循环获取父组成员的姓名,并与新成员的名字相比,无以复加,并毫无疑问的成员确实存在。

I ran a foreach loop to get the names of the members of the parent group, and compared with the new member name to be added and there is no doubt the member does exist.

我可以使用LINQ做字符串比较的名称,但其效果并不理想。

I could use LINQ to do string comparison on name, but its not ideal.

什么?如果有什么事情我做错了什么?有没有更好的方法来确定是否存在组在一组​​。

What? If anything am I doing wrong? Is there a better method to determine if a group exists in a group.

使用框架3.5 - 在此先感谢

Using framework 3.5 - thanks in advance

推荐答案

我知道这是有点晚了,但对于未来的参考,你可能想尝试。

I understand it's kind of late, but for future references you might want to try this.

public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp)
    {
        return gp.GetMembers(true).Contains(pgp);
    }

这篇关于GroupPrincipal.IsMemberOf始终返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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