我正致力於使用我的公司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