我需要检查当前用户是否是事件目录组的成员。我从获取当前用户开始,如下所示。现在我想知道如何检查此 CurrentUser 是否在事件目录组“CustomGroup”中
string CurrentUser = WindowsIdentity.GetCurrent().Name;
最佳答案
您可以使用 .NET 3.5 System.DirectoryServices.AccountManagement
类。请参阅 MSDN 文章 Managing Directory Security Principals in the .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
}
}
关于c# - 检查当前用户是否是事件目录组的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9152667/