title: How to connect to an active directory server?
body: <p>I'm using below code for connecting to an active directory server and retrieving its users.</p>
  
  <p>But my web server is not in sub domain. Can I connect to it?</p>
  
  <p>Or I should include its Ip address or something else? </p>
  
  <pre><code>DirectoryEntry entry = new DirectoryEntry("LDAP://dps.com", "Raymond", "xxxxxxx");
  
  DirectorySearcher mySearcher = new DirectorySearcher(entry);
  mySearcher.Filter = ("(&amp;(objectCategory=person)(objectClass=user))");
  
  foreach (SearchResult result in mySearcher.FindAll())
  {
     ResultPropertyCollection myResultPropColl = result.Properties;
     DataRow dr=reader.Tables[0].NewRow();
     dr[0]=myResultPropColl["samaccountname"][0].ToString()+"@"+Domain;
     reader.Tables[0].Rows.Add(dr);
     Response.Write(myResultPropColl["samaccountname"][0].ToString());
  }
  </code></pre>