我需要检查当前用户是否是活动目录组的成员。我首先获取当前用户,如下所示。现在我想知道如何检查此 CurrentUser 是否在活动目录组“CustomGroup”中
string CurrentUser = WindowsIdentity.GetCurrent().Name;
您可以使用.NET 3.5System.DirectoryServices.AccountManagement
类。请参阅 MSDN 文章管理 .NET Framework 3.5 中的目录安全主体了解详情。你可以使用类似的东西:
string CurrentUser = WindowsIdentity.GetCurrent().Name;
PrincipalContext context = new PrincipalContext(ContextType.Domain, "Domain");
UserPrincipal upUser = UserPrincipal.FindByIdentity(context, CurrentUser);
if(upUser != null)
{
if (upUser.IsMemberOf(context, IdentityType.SamAccountName, "CustomGroup"))
{
// The user belongs to the group
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)