C#/ DirectoryEntry /所有组/过滤

时间:2014-07-22 12:01:35

标签: c# asp.net filter active-directory-group directoryentry

我搞砸了获取所有递归组的完整且可用的列表,以填充下拉列表控件以选择要在ASP.net页面内管理的组。

使用过的代码:

List<string> groups = new List<string>();

using (DirectorySearcher searcher = new DirectorySearcher(dEntry))
{
    searcher.Filter = "(objectCategory=group)";
    foreach (SearchResult result in searcher.FindAll())
    {
        string group = result.Path.Substring(result.Path.IndexOf("/CN=")+4);
        string formatedResult = group.Substring(0, group.IndexOf(",CN="));
        groups.Results.Add(formatedResult);
    }
}

结果列表很长,包含一堆不需要的系统组。 只有特定的系统组才应包含在组列表中,例如“管理员”和所有“非系统定义”或“系统相关”组。 (如:AD-Structure中定义的部门,应用程序组等)。

任何提示如何使用DirectoryEntry做到这一点?

2 个答案:

答案 0 :(得分:0)

我已成功使用以下链接中的示例。我用它来搜索AD中的用户名,但它可以被修改。

AccessingtheActiveDirectoryfromMicrosoftNET

答案 1 :(得分:0)

如果groupType属性中存在0x1标志,则该组由系统创建。 可以修改过滤器以搜索:

系统组:

(&(objectCategory=group)(groupType:1.2.840.113556.1.4.803:=1))

非系统组:

(&(objectCategory=group)(!(groupType:1.2.840.113556.1.4.803:=1)))