Active Directory authentication in ASP.NET

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.

c#
c#-4.0
active-directory
c#-3.0
asked on Stack Overflow Oct 3, 2012 by Awadhendra • edited Oct 4, 2012 by Awadhendra

1 Answer

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).

answered on Stack Overflow Oct 3, 2012 by Jason Sperske • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0