查看用户是否属于 C# + Asp.net 中的 Active Directory 组 [英] See if user is part of Active Directory group in C# + Asp.net

查看:36
本文介绍了查看用户是否属于 C# + Asp.net 中的 Active Directory 组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来查看用户是否属于我的 .Net 3.5 asp.net c# 应用程序中的活动目录组.

I need a way to see if a user is part of an active directory group from my .Net 3.5 asp.net c# application.

我正在使用 msdn 的标准 ldap 身份验证示例,但我真的不知道如何检查组.

I am using the standard ldap authentication example off of msdn but I don't really see how to check against a group.

推荐答案

With 3.5 and System.DirectoryServices.AccountManagement 这更简洁一些:

With 3.5 and System.DirectoryServices.AccountManagement this is a bit cleaner:

public List<string> GetGroupNames(string userName)
{
  var pc = new PrincipalContext(ContextType.Domain);
  var src = UserPrincipal.FindByIdentity(pc, userName).GetGroups(pc);
  var result = new List<string>();
  src.ToList().ForEach(sr => result.Add(sr.SamAccountName));
  return result;
}

这篇关于查看用户是否属于 C# + Asp.net 中的 Active Directory 组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆