我创建了一个函数,可以一次将一个用户添加到特定组(管理员等),但响应 GroupPrinciple(5-10 秒)和 group.members.add(5-10 秒)调用似乎需要很长时间并减慢我的应用程序,响应需要将近 15-20 秒,有没有更快的方法来做到这一点?
private static void Add()
{
var userContext = new PrincipalContext(ContextType.Domain);
var user = new UserPrincipal(userContext);
user.SamAccountName = "c1111111";
var searcher = new PrincipalSearcher(user);
user = searcher.FindOne() as UserPrincipal;
var machineContext = new PrincipalContext(ContextType.Machine, "ABCDEFGHI1",
null, ContextOptions.Negotiate, "c123789", "test123");
var group = GroupPrincipal.FindByIdentity(machineContext,"Administrators");
group.Members.Add(user);
Console.WriteLine("saving group");
group.Save();
}