Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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-迁移到System.DirectoryServices.AccountManagement_C#_Active Directory - Fatal编程技术网

C#Active Directory-迁移到System.DirectoryServices.AccountManagement

C#Active Directory-迁移到System.DirectoryServices.AccountManagement,c#,active-directory,C#,Active Directory,我正在尝试将一些代码迁移到.NET 3.5中引入的System.DirectoryServices.AccountManagement类 我的旧代码是这样工作的,并继续工作: var directoryEntry = new DirectoryEntry("LDAP://{ip address}", "{domain}\\{users}", "{password}", AuthenticationTypes.Secure); 我的新代码在同一个项目下的同一台计算机上运行时不起作用: var p

我正在尝试将一些代码迁移到.NET 3.5中引入的System.DirectoryServices.AccountManagement类

我的旧代码是这样工作的,并继续工作:

var directoryEntry = new DirectoryEntry("LDAP://{ip address}", "{domain}\\{users}", "{password}", AuthenticationTypes.Secure);
我的新代码在同一个项目下的同一台计算机上运行时不起作用:

var principalContext = new PrincipalContext(ContextType.Domain, "{domain}", "ldap://{ip address}/DC=company,DC=local", ContextOptions.Negotiate, "{users}", "{password}");
新代码抛出一个错误“无法联系服务器”,我觉得它应该连接,因为它运行的是同一台机器,在同一个VisualStudio项目下


有什么建议吗?

在这种情况下,第四个参数的正确输入就是
DC=company,DC=local

谢谢,我也试过了,但还是有同样的错误。我应该注意,我是通过VPN连接的,但我不确定这有什么关系,因为使用VPN时,使用旧的DirectoryEntry方法仍然有效。这可能是VPN上的名称解析问题。您的第一个示例使用IP(顺便说一句,这不是一个好主意),后者将调用Windows API来查找DC。在重新设置问题时,您可能希望获取网络跟踪。