gpt4 book ai didi

c# - 检查当前用户是否是事件目录组的成员

转载 作者:太空狗 更新时间:2023-10-30 00:08:23 24 4
gpt4 key购买 nike

我需要检查当前用户是否是事件目录组的成员。我从获取当前用户开始,如下所示。现在我想知道如何检查此 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com