【发布时间】:2016-05-23 07:03:00
【问题描述】:
我需要检查登录到我正在制作的控制台应用程序的用户是否属于 DL(我们称之为 DL-A)。
某些用户不是 DL-A 的直接成员,而是属于 DL-A 成员的其他 DL。我工作的代码只检查用户直接所属的组。如何检查?
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, username);
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "DL-A");
if (user != null)
{
if (user.IsMemberOf(group))
{
...
}
}
【问题讨论】:
标签: authentication active-directory active-directory-group