简体   繁体   English

获取PrincipalContext的连接服务器以获取全局编录

[英]Get the connected server of a PrincipalContext for global catalog

I have a method CreateContextForGlobalCatalog that returns a PrincipalServer that connects to a global catalog: 我有一个方法CreateContextForGlobalCatalog ,它返回一个连接到全局编录的PrincipalServer

PrincipalContext = new PrincipalContext(ContextType.Domain,
                                        "forest.name:3268", 
                                        "dc=forest,dc=name", 
                                        ContextOptions.Negotiate, 
                                        userName, password);

Note: That is a reduced version of the method, normally the name and the container are parameters. 注意:这是方法的简化版本,通常名称和容器是参数。

With this context I'm looping over objects from the database to get information from the global catalog in ActiveDirectory: 在这个上下文中,我循环遍历数据库中的对象,以从ActiveDirectory中的全局编录中获取信息:

using (PrincipalContext principalContext = CreateContextForGlobalCatalog())
{
    foreach (ADAccount adAccount in accounts){
       Log.Debug("Connected server: " + principalContext.ConnectedServer);

    // get some information from AD here ...
    }
}

The Log.Debug line logs the connected server from the PrincipalContext. Log.Debug行从PrincipalContext记录连接的服务器。 I have a test setup containing only virtual machines. 我有一个只包含虚拟机的测试设置。

My Problem: When I now disconnect that connected server (disable network adapter) I don't get an exception and get connected to a new server but the log messages still shows the original connected server albeit the server is not available anymore. 我的问题:当我现在断开连接的服务器(禁用网络适配器)时,我没有得到异常并连接到新服务器,但日志消息仍显示原始连接的服务器,尽管服务器不再可用。

Is there a way to somehow refresh the connected server property or to get the information from somewhere else? 有没有办法以某种方式刷新连接的服务器属性或从其他地方获取信息?

不幸的是,它永远不会在启动后更新,你可以做的唯一的解决方法是重新检查每次迭代,如果你仍然连接或不

最简单的解决方案可能是尝试使用.Net的Ping类ping远程服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM