我正致力于使用我的公司AD对用户进行身份验证。此代码正在工作,但需要超过25-30秒才能返回DirectorySearcher结果。我能做些什么来改善响应时间?System.DirectoryServices很慢
public bool ADauthentication(string userName,string password)
{
try
{
string domain = ConfigurationManager.AppSettings["DirectoryDomain"];
string path = ConfigurationManager.AppSettings["DirectoryPath"];
string domainAndUserName = domain + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(path+"CN=Users,DC=myDomain,DC=com", userName, password);
entry.AuthenticationType = AuthenticationTypes.Secure;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName+")";
search.PropertiesToLoad.Add("CN");
SearchResult result = search.FindOne();
if (result == null)
{
return false;
}
return true;
}
catch(Exception ex)
{
log.Error($"Error: {ex.ToString()}");
return false;
}
}
一种方法是,以减少目录中的用户数。 – itsme86