Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查Active Directory组是否是另一个Active Directory组的成员_C#_.net_Active Directory_Active Directory Group - Fatal编程技术网

C# 如何检查Active Directory组是否是另一个Active Directory组的成员

C# 如何检查Active Directory组是否是另一个Active Directory组的成员,c#,.net,active-directory,active-directory-group,C#,.net,Active Directory,Active Directory Group,假设用户johnsmith是活动目录组MyManagers的成员。 假设MyManagers组是MyEmployees组的成员。 假设MyEmployees组是MyUsers组的成员 当johnsmith登录到我的应用程序时,我怎么知道他是MyUsers组的成员 欣赏C#中的例子 谢谢, kruvi如果您使用的是.NET 3.5及更高版本,则应检查System.DirectoryServices.AccountManagement(S.DS.AM)命名空间。请在此处阅读所有相关内容: 基

假设用户johnsmith是活动目录组MyManagers的成员。 假设MyManagers组是MyEmployees组的成员。 假设MyEmployees组是MyUsers组的成员

当johnsmith登录到我的应用程序时,我怎么知道他是MyUsers组的成员

欣赏C#中的例子

谢谢,
kruvi

如果您使用的是.NET 3.5及更高版本,则应检查
System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间。请在此处阅读所有相关内容:

基本上,您可以定义域上下文并在AD中轻松找到用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.Current; // this would be John Smith

if(user != null)
{
   // get the user's groups he's a member of
   PrincipalSearchResult<Principal> results = user.GetAuthorizationGroups();

   // now you just need to iterate over the groups and see if you find the
   // one group you're interested in
}
//设置域上下文
PrincipalContext ctx=新PrincipalContext(ContextType.Domain);
//查找用户
UserPrincipal user=UserPrincipal.Current;//这将是约翰·史密斯
如果(用户!=null)
{
//获取用户所属的组
PrincipalSearchResult results=user.GetAuthorizationGroups();
//现在,您只需要遍历这些组,看看是否找到
//一个你感兴趣的群体
}
S.DS.AM中的
GetAuthorizationGroups
调用确实会进行递归查询,例如,由于组是其他组的成员,因此它还会提取用户所属的任何组

新的S.DS.AM使得在广告中与用户和群组进行互动变得非常容易