Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance problems when using PrincipalContext.ValidateUser

I am using the solution discussed here to authenticate users against the active directory in my ASP.NET web application. I've written a simple ADMembershipProvider class thas is used together with FormsAuthentication. Works fine when running the project locally but when deployed to a server in the network, the ValidateUser call takes really long time (approx 20s).

//Assumes using System.DirectoryServices.AccountManagement
public override bool ValidateUser(string username, string password) {
    using (var context = new PrincipalContext(ContextType.Domain)) {
        return context.ValidateCredentials(username, password);
    }
}

I tried to add name and container parameters as documented on msdn to the PrincipalContext constructor, but these parameters doesn't seem to have any effect whatsoever.

using (var context = new PrincipalContext(ContextType.Domain, "MyDomain", "OU=MyCompany,DC=some,DC=stuff")) {
    return context.ValidateCredentials(username, password);
}

We have the same problem on at least two different servers in our network. The servers are connected to the AD and running OS Windows server 2003 SP2 (IIS6)

One idea I had was that the issue might be connected to the fact that our domain has some trusts to other domains, and that they are somehow involved when validating the user. However, the users we are trying to validate exists exclusively in "our" AD.

like image 845
Emil G Avatar asked Oct 14 '22 19:10

Emil G


1 Answers

Hit this issue and had to use ValidateCredentials(string, string, ContextOptions) method to pass in proper enum combination to access our ActiveDirectory connection in our environment.

like image 144
Brett Veenstra Avatar answered Nov 03 '22 04:11

Brett Veenstra