locked
high concurrency,principalContext.ValidateCredentials,slow RRS feed

  • Question

  • Hi.

    I run a ASP.NET web site.This web site need authentication people with Microsoft ActiveDirectory.Threr are more than 500 thousand user ,10 thousand OrganizationUnit on the Domain Controller.

    I wrote a function to validate people in a static class:

    static public string ValidateCredentials(string userName, string password)
            {
                string result = null;
                try
                {
                    log4net.ILog log = log4net.LogManager.GetLogger("Login.Aspx");
                    DateTime time0 = DateTime.Now;
                    PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, StsDomainName, StsAdRootOu + "," + StsDomainDn , ContextOptions.SimpleBind,StsAdUserName, StsAdUserPswd);
                    
                    
                    if (principalContext.ValidateCredentials(StsDomainShrotName +"\\" + userName, password,ContextOptions.SimpleBind))
                        result = "1";
                    else
                        result = "0";
                    log.Debug("Time cost:" + (DateTime.Now - time0).TotalMilliseconds + "DC:" + principalContext.ConnectedServer);
                    //principalContext.Dispose();
                }
                catch (Exception e)
                {
                    result = e.Message;
                }
                
                return result;

    During hign concurrency scence, more than 2000 user login the web site at the same time. I found it cost a long time to do the validation.

    But if i dim the principalContext  as a static member of the class,the time cost on validation will be cut down.But the CPU usage on the web site server will raise to 90%.

    anyone can help me to improve my code


    ...

    Thursday, August 27, 2015 5:50 AM