0

我有两个信任林 A 和 B,用户 C 属于林 A,组 D 属于林 B。然后我将用户 C 分配给组 D。

我的问题是,我想获得用户 C 的所有成员资格。有人知道如何在 C# 中做到这一点吗?

我尝试了一些 .net API,但我只是为用户获取了当前域的成员资格。我知道“成员”属性存储成员资格,但我是否需要搜索信任林中的所有组并检查“成员”属性才能实现这一点?

下面的测试程序是我试图获得信任林成员资格的程序。域“a.com”来自林 A,域“b.com”来自林 B。

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "a.com"))
{
    using (PrincipalContext ctx2 = new PrincipalContext(ContextType.Domain, "b.com"))
    {
        UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "C");
        var groups1 = user.GetGroups(ctx); // only get the memebership of a.com
        var groups2 = user.GetGroups(ctx2); // cannot get the membership of b.com
    }
}

谢谢。

4

0 回答 0