【发布时间】:2020-12-15 16:41:55
【问题描述】:
我有以下代码,它检索特定用户所属的所有活动目录组:-
string[] output = null;
using (var ctx = new PrincipalContext(ContextType.Domain, "???.???.uk"))
using (var user = UserPrincipal.FindByIdentity(ctx, username))
{
if (user != null)
{
output = user.GetGroups() //this returns a collection of principal objects .Select(x => x.SamAccountName) // select the name. you may change this to choose the display name or whatever you want
.ToArray(); // convert to string array
}
}
我遇到的唯一问题是域控制器关闭时。我认为上面的代码会简单地查看其他控制器,直到找到一个启动的控制器。上面的代码怎么改写,才不会在单个域控制器不可用的情况下崩溃?
谢谢
【问题讨论】:
-
在断开以太网电缆的情况下运行代码会发生什么?
标签: c# active-directory