我们有一个winforms应用程序,它从活动目录中获取组。现在一切正常,直到我们将旧的域控制器换成了新的域控制器。
从那时起,我们的应用程序在调用方法 UserPrincipal.GetGroups()时引发异常。抛出异常是因为它尝试连接到旧的DC。
异常消息已翻译:
服务器无法运行surottdc04.TOSOT.CH
如果旧的dc信息缓存在某个地方或应用程序从哪里获取旧信息,有人有任何想法吗?
在以下屏幕截图中,您可以看到引发异常的代码部分:
如您所见,在监视窗口中,有一个正确的新DC surottdc06 ,这是从当前登录用户的上下文中正确获取的。但例外情况是,仍然有旧的DC surottdc04 ,为什么?
更新
到目前为止,我们发现当我们将上下文作为参数传递给该方法时,它可以工作,但是没有上下文,该方法将尝试连接到旧的DC。
这是一种可能的解决方案,但问题仍然是,当该方法称为无参数时,该方法在哪里获取旧的DC信息并尝试在那里连接?
public void GetGroups()
{
var sid = WindowsIdentity.GetCurrent().User.Value;
using (var context = new PrincipalContext(ContextType.Domain, "tosot.ch"))
{
using (var userPrinciple = UserPrincipal.FindByIdentity(context, sid))
{
/*
* this works, we just pass the context which we've used to
* create the UserPrincipal instance again to fetch the groups
*/
var ret = userPrinciple.GetGroups(context);
/*
* this works NOT: when calling without context argument,
* it seems, the context used is not the same
* as the userPrinciple instance is linked to.
* Instead it uses a selfmade context with an yet exsting,
* but currently not online domain controller - why that??
* (this 'old' domain controller is currently not running,
* but it's yet not removed from the domain ...)
*/
ret = userPrinciple.GetGroups();
}
}
}
答案 0 :(得分:0)
我的猜测是DNS仍在返回旧DC的IP。
从命令行运行:
nslookup tosot.ch
您看到surottdc04的IP吗?如果是这样,那就是您的问题。
我从未遇到过解决此问题的方法。这些说明可能会有所帮助,但看起来像是一篇老文章,因此可能不再以相同的方式完成:https://support.microsoft.com/en-us/help/555846
更新:或者您可以使用C#查看当前域看到的DC。看看旧的还是仍然出现:
foreach (DomainController dc in Domain.GetCurrentDomain().DomainControllers) {
Console.WriteLine(dc.Name);
}