title: Active Directory authentication in ASP.NET
body: <p>I am trying to implement active directory authentication but I am getting exception which is like </p>
  
  <pre><code>System.Runtime.InteropServices.COMException was caught
    Message=Unknown error (0x80005000)
    Source=System.DirectoryServices
    ErrorCode=-2147463168
    StackTrace:
         at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
         at System.DirectoryServices.DirectoryEntry.Bind()
         at System.DirectoryServices.DirectoryEntry.get_AdsObject()
         at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
         at System.DirectoryServices.DirectorySearcher.FindOne()
         at ConsoleApplication1.ADAuthentication.AuthenticateADUsers(String userNameWithDomain, String password) in C:\Users\awadhendrat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 83
         at ConsoleApplication1.Program.Main(String[] args) in C:\Users\awadhendrat\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 23
    InnerException: 
  </code></pre>
  
  <p>I don't know what I am missing. Following code I have written for implementing AD Authentication.</p>
  
  <pre><code>public bool AuthenticateADUsers(string userNameWithDomain, string password)
          {
              DirectoryEntry objDirectoryEntry = null;
              DirectorySearcher objDirectorySearcher = null;
  
              try
              {
                  objDirectoryEntry = new DirectoryEntry("https://ab.hotels.com/", userNameWithDomain, password, AuthenticationTypes.Delegation);
                  objDirectorySearcher = new DirectorySearcher(objDirectoryEntry);
                  objDirectorySearcher.Filter = string.Format("(&amp;(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", userNameWithDomain.Substring(0, userNameWithDomain.IndexOf('@')));
                  objDirectorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress");
                  var result = objDirectorySearcher.FindOne();
                  if (result != null)
                      return true;
                  else
                      return false;                           
              }
              catch
              {
                  throw;
              }
          }
  </code></pre>
  
  <p>I have done some google but not getting helpful. Here I have few confusion like every where they written LDAP://somedomain/ but here I have <a href="https://somedomain.com" rel="nofollow">https://somedomain.com</a> another confusion is my test application is on one domain and provided domain is on another server. </p>
  
  <p>When I open links provided by client which is used for AD Authentication then it opens Open Office Web Access. </p>
  
  <p>I don't how to solve this problem. </p>
  
  <p>Thanks.</p>