79144506

Date: 2024-10-31 11:28:42
Score: 0.5
Natty:
Report link

This is what I have discovered from here:

Binding against the AD has a serious overhead, the AD schema cache has to be loaded at the client (ADSI cache in the ADSI provider used by DirectoryServices). This is both network, and AD server, resource consuming - and is too expensive for a simple operation like authenticating a user account.

While it does not explain the behaviour of why the try-catch does not catch the error, it did point me to a workable solution using PrincipalContext instead.

This works without any delay or error:

private bool AuthenticateUser(string userName, string password)
{
    using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "EnterYourDomain"))
    {
        return context.ValidateCredentials(userName, password);
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Alan