gpt4 book ai didi

c# - 使用 System.DirectoryServices.AccountManagement 我收到奇怪的错误

转载 作者:行者123 更新时间:2023-11-30 22:21:07 25 4
gpt4 key购买 nike

当我运行下面的代码来检索所有组、子组和相关用户时,我在检索一些记录后收到一个奇怪的错误:我期望检索 90000 个组/子组和 250000 个用户

错误:

System.Runtime.InteropServices.COMException was caught Message=The server is not operational

 public static List<Group>getUsers()
{

// create the "context" in which to operate - your domain here,
// as the old-style NetBIOS domain, and the container where to operate in
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "lin.proximus.com");

// define a "prototype" - an example of what you're searching for
// Here: just a simple GroupPrincipal - you want all groups
GroupPrincipal prototype = new GroupPrincipal(ctx);

// define a PrincipalSearcher to find those principals that match your prototype
PrincipalSearcher searcher = new PrincipalSearcher(prototype);

// define a list of strings to hold the group names
List<Group> groupNames = new List<Group>();
int counter = 0;
// iterate over the result of the .FindAll() call
foreach (var gp in searcher.FindAll())
{

// cast result to GroupPrincipal
GroupPrincipal groupPrincipal = gp as GroupPrincipal;

// if everything - grab the group's name and put it into the list
if (groupPrincipal == null) continue;

Group group = new Group();
group.Name = groupPrincipal.Name;
group.Description = groupPrincipal.Description;
AddSubGroups(groupPrincipal, ref group);
AddMemebers(groupPrincipal, ref group);
counter++;
groupNames.Add(group);
Console.WriteLine(counter);
if (counter > 10000)
return groupNames;
}
return groupNames;
}

private static void AddSubGroups(GroupPrincipal gp,ref Group gr)
{
gr.SubCounts = 0;
if (gp.GetGroups().Count() <= 0) return;

gr.SubCounts = gp.GetGroups().Count();
gr.SubGroups = new List<string>();
foreach (var principal in gp.GetGroups())
{
gr.SubGroups.Add(principal.Name);
}
}

private static void AddMemebers(GroupPrincipal gp, ref Group gr)
{
if (gp.GetMembers().Count() <= 0) return;

gr.Users = new List<string>();

foreach (Principal principal in gp.GetMembers())
{
gr.Users.Add(principal.Name);
}
}

有什么想法吗?

最佳答案

看起来你可以设置 DirectorySearcher.PageSize并做一个分页结果集。这通常可以让您突破服务器端限制。

我仍然会尝试使用已知的 LDAP 工具(我喜欢 Apache Studio),看看它是否有效。 (directory.apache.org/studio)

关于c# - 使用 System.DirectoryServices.AccountManagement 我收到奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14560858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com