LDAP Problem in ASP.Net Application

Dear Experts,

We have an ASP.Net application and this application uses LDAP for authentication. In other words, the application is authenticated by users from Windows Active Directory. Our application uses system.directoryservices.dll. By the way, when we install the application on a non-domain controller, we are unable to get domain user list although we are able to get domain user list using ldp.exe (MS LDAP Tool) on the same computer. Both for application and LDP.exe, we use port 389, along with DNS name of DC with valid domain user name and password. While LDP.exe (Microsoft LDAP tool) is working correctly, the application is unable to get anything from domain even we use the same LDAP filter rule for both.

Example Code Segments from Application:

// ActiveDirectory.cs
 public List<SearchResult> getAllByQuery(string query)
      List<SearchResult> result = new List<SearchResult>();

      // entry is an ActiveDirectory's "DirectoryEntry" attribute -> (*1)
      DirectorySearcher srch = new DirectorySearcher(entry, query); // System.DirectoryServices.dll, v2.0.50727

      SearchResultCollection results = srch.FindAll();
      foreach (SearchResult item in results)
      return result;


if (byUsername)
      return ldapLogin.getUserClassByQuery("(&(|(objectclass=user)(objectclass=person))(sAMAccountName=" + name + ")(!userAccountControl:1.2.840.113556.1.4.803:=2))"); //( selected one *)
      return ldapLogin.getUserClassByQuery("(&(|(objectclass=user)(objectclass=person))(displayName=" + name + ")(!userAccountControl:1.2.840.113556.1.4.803:=2))");

if (byUsername)
      return ldapLogin.getUserClassByQuery("(&(objectCategory=person)(objectClass=user)(sAMAccountName=" + name + ")(!userAccountControl:1.2.840.113556.1.4.803:=2))"); //( selected one *)
      return ldapLogin.getUserClassByQuery("(&(objectCategory=person)(objectClass=user)(displayName=" + name + ")(!userAccountControl:1.2.840.113556.1.4.803:=2))");

Could you please help us?

Best Regards
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Maybe this will help.

... demonstrates how an ASP.NET application can use Forms authentication to permit users to authenticate against Active Directory using the Lightweight Directory Access Protocol (LDAP). After the user is authenticated and redirected, you can use the Application_AuthenticateRequest method of the Global.asax file to store a GenericPrincipal object in the HttpContext.User property that flows throughout the request.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.