无法从远程服务器访问 Active Directory 域控制器

Can not access Active Directory domain controller from remote server

我对 LDAP 和 Active Directory 集成部分还很陌生。虽然我已成功配置我的本地计算机以访问 Active Directory 域控制器,但当我将它部署到我们的一台服务器上时,既不能通过域的 IP 地址也不能通过域名访问它。

我的网站使用 ASP.NET C#。

收到此错误:

The specified domain either does not exist or could not be contacted.

我写的访问AD的方法在这里:

private SearchResultCollection sResults { get; set; }
sResults = null;

public void SearchByUsername(string username)
{
   try
   {
       // initiate a directory entry
       private const string ldapPath = "LDAP://192.168.0.190/OU=Domain   Users,DC=mydomain,DC=net"                
       dEntry = new DirectoryEntry(ldapPath);

       dSearcher = new DirectorySearcher(dEntry);
       dSearcher.Filter = "(&(objectClass=user)(sAMAccountname= " + username +  "))";

       performSearch();
       getValues();
    }
    catch (Exception)
    {
        throw;
    }
}

private void performSearch()
{
    // perform search in Active Directory
    sResults = dSearcher.FindAll();
}

private void getValues()
{
    // loop through results of search
    foreach (SearchResult sResult in sResults)
    {
        Employee emp = new Employee();

        emp.CN = getProperty(sResult, "cn");
        emp.FirstName = getProperty(sResult, "givenName");
        emp.LastName = getProperty(sResult, "sn");
        emp.Username = getProperty(sResult, "sAMAccountname");
        emp.Email = getProperty(sResult, "mail");

        Employees.Add(emp);
    }
}

以上方法在我的本地机器上使用 IP 地址和域名都非常有效。我尝试使用它的服务器是 Windows Server 2012 R2。

我 运行 命令 nltest /dclist:mydomain.net 并确保服务器在域内,因为它返回了我的详细信息。即 DC 名称、IP 地址、域名。

我 运行 有什么语法问题吗?或者它是否与 DNS 等配置问题有关?

此外,想提一下,因为我尝试在 www.serverfault.com 上搜索此内容,但无法收集到太多细节。

请指点方向。

事情似乎终于解决了。

之前我提到我确保我正在使用的机器在域中,但那里的情况略有不同。我试图让事情正常运行的机器实际上不在域中,而是在工作组中。

下面的两个 Netdom 命令帮助我识别了这种情况。

  1. netdom 验证 - 使用此命令发现计算机尚未加入域。
  2. netdom join - 使用此命令,能够将计算机加入网络域。

参考:https://technet.microsoft.com/en-us/library/cc772217.aspx

一旦进入域,Active Directory 就可以立即访问。