Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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# 在c中使用vpn进行Active directory身份验证#_C#_Active Directory_Vpn - Fatal编程技术网

C# 在c中使用vpn进行Active directory身份验证#

C# 在c中使用vpn进行Active directory身份验证#,c#,active-directory,vpn,C#,Active Directory,Vpn,我正在开发一个web应用程序,该应用程序根据Active Directory服务器对用户进行身份验证。现在,如果我在该AD服务器的域下从开发PC运行我的代码,我的代码运行平稳。我们需要运行的代码从一个完全不同的网络使用VPN和这里的发展个人电脑没有进入该广告。我得到以下错误,而试图访问广告服务器 指定的域不存在或无法联系 我的VPN工作正常。我可以使用这个VPN访问远程桌面。我知道解决这个问题需要做一些调整,但找不到。我浏览了以下链接,但找不到任何解决方案 以下是我在web.config &

我正在开发一个web应用程序,该应用程序根据Active Directory服务器对用户进行身份验证。现在,如果我在该AD服务器的域下从开发PC运行我的代码,我的代码运行平稳。我们需要运行的代码从一个完全不同的网络使用VPN和这里的发展个人电脑没有进入该广告。我得到以下错误,而试图访问广告服务器

指定的域不存在或无法联系

我的VPN工作正常。我可以使用这个VPN访问远程桌面。我知道解决这个问题需要做一些调整,但找不到。我浏览了以下链接,但找不到任何解决方案

  • 以下是我在
    web.config

    <appSettings>
       <add key="LDAPPath" value="LDAP://DC=MYSERVER,DC=COM" />
       <add key="ADGroupName" value="Analyst"/>
    </appSettings>
    

    任何帮助都将不胜感激。谢谢。

    我有一个类似的问题,虽然比较简单。我成功地使用了以下代码:

    private bool DoLogin(string userName, string password)
    {
        using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "DomainName.com")) {
            bool isValid = pc.ValidateCredentials(userName, password);
            if (isValid) {
                // authenticated
                ...
                return true;
            }
            else {
                // invalid credentials
                ...
                return false;
            }
        }
    }
    

    在域名末尾使用“.com”对我来说很重要。如果没有它,我会出现与你描述的症状相同的症状。

    我刚刚解决了几个小时。在网络上没有问题,通过VPN连接时有很多问题。似乎当您通过VPN连接时,DirectoryEntry的“连接字符串”必须更加精确。我终于让它使用LDAP地址/连接字符串,如下所示:

    LDAP://ip_of_primary_domain_controller/fully qualified path of the container object where the binding user is located
    
    举个例子,这样的事情对我很有用:

    DirectoryEntry directoryEntry = new DirectoryEntry(
          "LDAP://192.168.0.20/OU=Service Accounts,OU=Admin Accounts,DC=myserver,DC=com",
          "username@myserver.com", "password"); 
    
    。。。“在哪里”username@myserver.com位于OU=服务帐户、OU=管理员帐户、DC=myserver、DC=com中。如果使用SysInternals ADExplorer(或类似工具)搜索用户名,它将告诉您容器的正确完全限定路径

    有关“连接字符串”中应该包含哪些内容的详细答案,请参见此处:

    DirectoryEntry directoryEntry = new DirectoryEntry(
          "LDAP://192.168.0.20/OU=Service Accounts,OU=Admin Accounts,DC=myserver,DC=com",
          "username@myserver.com", "password");