0

I am doing password verification against Active Directory using the following code. The query takes 4 seconds.

Why is it so slow?

DirectoryEntry searchRoot = new DirectoryEntry(
        "LDAP://ldap.subdomain.com:636/cn=serviceaccount,OU=serviceaccounts,DC=domain,DC=internal",
        username,
        password,
        AuthenticationTypes.Secure);

    try
    {
        DirectorySearcher ds = new DirectorySearcher(searchRoot);
        ds.FindOne();
        // Success!
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
        // Failure
    }
Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
mmcglynn
  • 7,668
  • 16
  • 52
  • 76
  • If you're using .NET 3.5 or newer, check out [my answer to this similar SO question](http://stackoverflow.com/questions/290548/c-sharp-validate-a-username-and-password-against-active-directory/499716#499716) on how to do it differently - **not** using a slow `DirectorySearcher`, but a native validation method – marc_s Feb 21 '12 at 15:37
  • Like a lot of others on SO, I can't get PrincipalContext to work. – mmcglynn Feb 21 '12 at 18:49
  • That's the **first time** I've ever heard anyone having trouble with PrincipalContext - can you be **a bit more specific** ?!?!?! Just saying *it doesn't work* and not giving any detailed information isn't really much to go on to help..... – marc_s Feb 21 '12 at 21:19
  • Returns the error message "The LDAP server is unavailable." Google has 81K results on that string. – mmcglynn Feb 22 '12 at 19:21

0 Answers0