I have using active directory login

I got some performance issue

This is my code

 public bool IsAuthenticated(String domain, String username, String pwd)
        {

            String domainAndUsername = domain + @"\" + username;
            DirectoryEntry entry = new DirectoryEntry("LDAP://" + _path, domainAndUsername, pwd);

            try
            {   //Bind to the native AdsObject to force authentication.         
                Object obj = entry.NativeObject;

                DirectorySearcher search = new DirectorySearcher(entry);

                search.Filter = "(SAMAccountName=" + username + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();

                if (null == result)
                {
                    return false;
                }

                //Update the new path to the user in the directory.
                _path = result.Path;
                _filterAttribute = (String)result.Properties["cn"][0];
            }
            catch (Exception ex)
            {
                throw new Exception("Error authenticating user. " + ex.Message);
            }

            return true;
        }

When i enter correct user name and password, it's work well and fast. But when i enter wrong username and password ,then it's loading very slow.


This two line coding

Object obj = entry.NativeObject;
 DirectorySearcher search = new DirectorySearcher(entry);

taking long time to return the result while login inputs are wrong.


So My question is

  • Why those line taking long time to load, whenever i put wrong login details?
  • Why those line taking quick time to load, whenever i put correct logindetails?

Already a person asked this question in SO

Is using DirectoryServices.NativeObject slow/bad?

But no one answering for that. Please tell me the solution :)

Related posts

Recent Viewed