2
votes

I am very new to the LDAP and Active Directory integration portion. Although I successfully configured my local machine to access Active Directory domain controller, when I deployed it on one of our server neither through IP address of the domain nor through domain name it was accessible.

My website is in ASP.NET C#.

It was getting this error:

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

My method written to access AD is here:

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);
    }
}

Above method works very well on my local machine both with IP address and domain name. Server where I am trying this to work is Windows Server 2012 R2.

I ran command nltest /dclist:mydomain.net and made sure that the server is within the domain as it returned me details. i.e. DC name, IP address, domain name.

Is there any syntactical issue I have run into? OR is it related to configuration issue like DNS ?

Also, like to mention as I tried searching about this on www.serverfault.com but couldn't gather much details.

Please suggest me direction.

1
are you familiar with PrincipalContext are you aware that you can capture the same information quicker and with less code also on the remote server do you have these assemblies / dll's in the GAC on the Remote Machine using System.DirectoryServices.ActiveDirectory; using System.DirectoryServices.AccountManagement;MethodMan
@MethodMan: I checked and found these dlls are there on remote machine. but their version is 4.0.**.** and the one which I have in my local machine has 4.6.**.**. Should I replace server ones with my local ones?Binoy

1 Answers

0
votes

Finally things seemed working out.

Earlier I mentioned that I made sure that the machine I am working on is in the domain but things were slightly different there. The machine I am trying to make things work is not actually in the domain but in the workgroup.

Below two Netdom commands helped me identifying this situation.

  1. netdom verify - with this command it is found that machine hasn't joined domain.
  2. netdom join - with this command, was able to join machine to network domain.

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

Once it is in domain, Active Directory became immediately accessible.