Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Active Directory中的用户身份验证-Windows Server 2012 R2_C#_Networking_Active Directory - Fatal编程技术网

C# Active Directory中的用户身份验证-Windows Server 2012 R2

C# Active Directory中的用户身份验证-Windows Server 2012 R2,c#,networking,active-directory,C#,Networking,Active Directory,在项目启动期间,Active Directory出现以下情况: 环境信息: 具有主Active Directory服务器的中心服务器:Windows server 2012 R2 64位,IP地址:192.168.1.10 具有只读Active Directory服务器的Office服务器:Windows server 2012 R2 64位,IP地址:192.168.50.10(此Active Directory从中央服务器复制用户和工作站信息)。这两台服务器通过DSL网络连接 我们的C#应用

在项目启动期间,Active Directory出现以下情况:

环境信息: 具有主Active Directory服务器的中心服务器:Windows server 2012 R2 64位,IP地址:192.168.1.10

具有只读Active Directory服务器的Office服务器:Windows server 2012 R2 64位,IP地址:192.168.50.10(此Active Directory从中央服务器复制用户和工作站信息)。这两台服务器通过DSL网络连接

我们的C#应用程序在办公网络上运行,运营商PC(Windows 7 64位)连接到办公室的域。它必须使用以下代码对Office Server中Active Directory中的用户进行身份验证

 using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "mydomain.com"))
                    {
                        // validate the credentials
                        bool isValid = pc.ValidateCredentials("username", "password");
                        Log("Create principal context done");
                    }
问题是,我们几乎每次尝试运行此代码时都会出现以下错误:

  • 服务器无法运行
  • 无法联系服务器
  • LDAP服务器不可用
  • 如果这段代码有效,大约需要1分钟才能完成。 注意:此代码在我们的开发环境(具有相同IP范围10.0.0的LAN网络)中从未失败


    有什么建议吗?

    您有防火墙或DNS问题吗


    是否确实调用了正确的服务器?

    PrincipalContext是否可能正在选择一个不在其他站点上的域,或者可能是另一个站点中不可路由的域?您是否已使用网络正确配置了站点和服务?您可以尝试使用PrincipalContext(ContextType,String,String)构造函数,并将要连接的特定DC传递给它,看看问题是否消失。