簡體   English   中英

AD - 使用 DirectoryEntry 搜索時出現 LDAP 錯誤超時

[英]AD - LDAP error timeout in search with DirectoryEntry

我用這個連接到 AD:

public void ValidateCredentials(string username, string password, out ClaimsIdentity identity)
    {
        using (DirectoryEntry entry = new DirectoryEntry())
        {
            entry.RefreshCache();
            entry.Username = username;
            entry.Password = password;
            DirectorySearcher searcher = new DirectorySearcher(entry);
            searcher.ClientTimeout = TimeSpan.FromMinutes(2);
            searcher.ServerTimeLimit = TimeSpan.FromMinutes(2);
            searcher.Filter = "(&(&(objectclass=user)(objectcategory=person))" +
            "sAMAccountName=" + username + ")";
            SearchResult srResult = searcher.FindOne();

            identity = new ClaimsIdentity();
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, username));
        }
    }

這樣,如果我輸入了錯誤的用戶名和密碼,它會給我一個錯誤的用戶名或密碼錯誤,如果我輸入了正確的用戶名和密碼,它允許我登錄,但是如果我輸入了一個存在的用戶名和錯誤的密碼,它給了我一個超時錯誤(30秒):

由於超時期限已過,此操作返回。

嘗試使用 ClientTimeout 和 ServerTimeLimit 增加超時時間,但沒有任何反應。

也嘗試這樣做:

string filter = "(&(&(objectclass=user)(objectcategory=person))" +
            "sAMAccountName=username)";
        NetworkCredential credentials = new NetworkCredential(username, password);
        LdapDirectoryIdentifier directoryIdentifier =
           new LdapDirectoryIdentifier("LDAP://DC=domain,DC=com", 389, false, false);
        using (LdapConnection connection =
           new LdapConnection(directoryIdentifier, credentials, AuthType.Basic))
        {
            connection.Timeout = new TimeSpan(0, 0, 90);
            connection.SessionOptions.ProtocolVersion = 3;
            SearchRequest search =
                new SearchRequest(username, filter, System.DirectoryServices.Protocols.SearchScope.Base, "mail");
            SearchResponse response = connection.SendRequest(search) as SearchResponse;
            foreach (SearchResultEntry entry in response.Entries)
            {
                Console.WriteLine(entry.Attributes["mail"][0]);
            }
        }

但是服務器給了我一個我不支持的錯誤。

我對想法持開放態度。

提前致謝。

問候

編輯:我補充說,如果它有任何用處,我們正在通過一個能夠減慢速度的 VPN 來做到這一點。

問題是他們給我的 LDAP url 沒有得到很好的優化,他們給了我一個新的 url 並且問題已解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM