在C#中搜索Active Directory用户只有在指定的组 [英] Searching Active Directory Users Only in Specified Group in C#

查看:147
本文介绍了在C#中搜索Active Directory用户只有在指定的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在苦苦寻找查询出指定的AD组的成员的好方法。

I have been struggling to find a good way to query out the members of a specified AD Group.

我在查找组,甚至是查询用户根据标准没有问题。

I have no issues in finding the group, or even querying users based on criteria.

目前我有

 PrincipalContext context = new PrincipalContext(ContextType.Domain, _domain, ADServerUser, ADServerPassword);
 UserPrincipal userPrinciple = new UserPrincipal(context);
 userPrinciple.GivenName = "stringToSearchForFirstName";
 userPrinciple.Name = "stringToSearchForUserName";
 userPrinciple.Surname = "stringToSearchForLastName";
 PrincipalSearcher srch = new PrincipalSearcher(new UserPrincipal(context));                    
 srch.QueryFilter = userPrinciple;
 var result = srch.FindAll();

这给我的一切,我希望用户,但它不会筛选组下降。

This give me all the users that I want, however it doesn't filter the group down.

我可以使用GroupPrinciple对象以及主要的搜索,但我无法过滤下来的用户。

I can use the GroupPrinciple Object along with the principal search, but then I can't filter down the Users.

我有种想能够同时适用于一个UserPrincipal和GroupPrincipal由团体和用户参数来筛选返回结果的方法。

I kind of want a way to be able to apply both a UserPrincipal and GroupPrincipal to filter the returned results by BOTH Group and User parameters.

我已经使用了LINQ where子句来尝试做一个比赛,看看用户是在一个组,但是当我得到所有用户的查询超时。有道理在所有。

I've used a linq where clause to try and do a match to see if the user is in a group but when i get all users the query times out. makes sense over all.

但是,如果我查询了团,我也没有办法使用principalSearcher申请查询。

However if i query out the group, I have no way of using the principalSearcher to apply the query.

这是如何做到这一点任何想法?

Any ideas on how to do this?

推荐答案

从我的研究,我得出的结论是使用主体对象,以便能够在两个组和用户参数过滤是不可能的。我们需要恢复使用查询字符串的方法来AD来解决这个问题。

From my research I have concluded that using the Principal Objects to be able to filter on both group and user parameters is not possible. we needed to revert to using query string methods to AD to solve the issue.

这篇关于在C#中搜索Active Directory用户只有在指定的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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