2

下面的代码几周前还在工作,但最近它停止获取许多用户帐户的组,我不知道发生了什么变化。代码没有改变。

.GetGroups()方法只返回一个组,上许多用户的域用户,但对于我的用户和其他几个用户,它确实返回了完整的组集合。

目标只是获取该用户所属的组列表。我对 Active Directory 结构了解不多。

using (var context = new PrincipalContext(ContextType.Domain, Environment.UserDomainName))
using (var user = UserPrincipal.FindByIdentity(context, Emply.Username))
    if (user != null)
    { 
        foreach (var gn in user.GetGroups())
        {
            groups += gn.Name + "|";
        }
    }
4

0 回答 0