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

标签 c# active-directory activedirectorymembership active-directory-group

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

相关文章:

azure - 隐藏 Azure Active Directory 登录页面中的后退按钮

c++ - 查找当前用户事件目录组 C++

c# - ActiveDirectoryMembershipProvider 验证用户

c# - 在 ASP.NET 中为购物车系统创建数量更新按钮

c# - 在路径/文件夹下注册HttpHandler

javascript - Window Active Directory React JS 自动身份验证

c# - 读取文本文件跳过一堆行然后继续其他行

c# - WPF应用程序是用什么语言开发的

java - Spring ldap 身份验证失败错误代码