0

I am trying to implement active directory authentication but I am getting exception which is like

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: 

I don't know what I am missing. Following code I have written for implementing AD Authentication.

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("(&(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;
            }
        }

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 https://somedomain.com another confusion is my test application is on one domain and provided domain is on another server.

When I open links provided by client which is used for AD Authentication then it opens Open Office Web Access.

I don't how to solve this problem.

Thanks.

Awadhendra
  • 355
  • 2
  • 10
  • 34

1 Answers1

0

According to this answer (and some quick code I wrote to test this), it's a permission problem (possibly related to your use of an https URL for the AD path, checkout this code for building a DirectoryEntry or the fact that you are doing a full AD search with the same user you are trying to authenticate).

Community
  • 1
  • 1
Jason Sperske
  • 29,816
  • 8
  • 73
  • 124
  • Ok. I have one confusion that can I use AD authentication for different domains like i am creating application on A domain and Active Directory is on B domain. – Awadhendra Oct 03 '12 at 17:43