locked
LDAP user Authentication using Directory searcher in c# RRS feed

  • Question

  • User620140571 posted

    We have an web application developed using c#(VS 2008/3.5 framework). The application uses the mode of authentication as "Windows" with a service account present in domain (Domain1) to run the application as ASP.Net user. We have authentication to be done for the users present in different domain (Domain 2). When authentication is done using the directory services(Directory searcher), we are able to connect to LDAP of domain1 and bind it, so that user is authenticated. Also, the user is able to be authenticated if the user has been migrated from domain1 to domain 2. However, if there is a user id directly created in domain 2, then application is not able to bind to Domain2 (during the LDAP authentication) and hence, this user is not being authenticated by the application. Please suggest the solution regarding the same.

    <authentication mode="Windows"/>
    <identity impersonate="true" userName="domain1\svc_acc" password="***"/>

    public bool ValidateUidPwdAndGetUserTypeGlobal(string TPXId, string password)
            {

                string strADPath = "LDAP://a.b.c/dc=a,dc=b,dc=c";
                try
                {
                    DirectoryEntry objDirEntry = new DirectoryEntry(strADPath, TPXId, password);
                    
                    DirectorySearcher search = new DirectorySearcher(objDirEntry);
                    search.Filter = "(samaccountname=" + TPXId + ")";
                    SearchResult result = search.FindOne();
                    if (null == result)
                    {
                        return false;
                    }
                    else
                        return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }

    Friday, January 11, 2013 5:45 AM

Answers