private Match ( Uri uri, string authenticationType ) : bool | ||
uri | Uri | |
authenticationType | string | |
리턴 | bool |
public NetworkCredential GetCredential(Uri uriPrefix, string authType) { if (uriPrefix == null) { throw new ArgumentNullException("uriPrefix"); } if (authType == null) { throw new ArgumentNullException("authType"); } int num = -1; NetworkCredential credential = null; IDictionaryEnumerator enumerator = this.cache.GetEnumerator(); while (enumerator.MoveNext()) { CredentialKey key = (CredentialKey)enumerator.Key; if (key.Match(uriPrefix, authType)) { int uriPrefixLength = key.UriPrefixLength; if (uriPrefixLength > num) { num = uriPrefixLength; credential = (NetworkCredential)enumerator.Value; } } } return(credential); }
public NetworkCredential GetCredential(Uri uriPrefix, string authenticationType) { if (uriPrefix == null) { throw new ArgumentNullException(nameof(uriPrefix)); } if (authenticationType == null) { throw new ArgumentNullException(nameof(authenticationType)); } if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential(uriPrefix=\"" + uriPrefix + "\", authType=\"" + authenticationType + "\")"); } if (_cache == null) { if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential short-circuiting because the dictionary is null."); } return(null); } int longestMatchPrefix = -1; NetworkCredential mostSpecificMatch = null; // Enumerate through every credential in the cache foreach (KeyValuePair <CredentialKey, NetworkCredential> pair in _cache) { CredentialKey key = pair.Key; // Determine if this credential is applicable to the current Uri/AuthType if (key.Match(uriPrefix, authenticationType)) { int prefixLen = key.UriPrefixLength; // Check if the match is better than the current-most-specific match if (prefixLen > longestMatchPrefix) { // Yes: update the information about currently preferred match longestMatchPrefix = prefixLen; mostSpecificMatch = pair.Value; } } } if (GlobalLog.IsEnabled) { GlobalLog.Print("CredentialCache::GetCredential returning " + ((mostSpecificMatch == null) ? "null" : "(" + mostSpecificMatch.UserName + ":" + mostSpecificMatch.Domain + ")")); } return(mostSpecificMatch); }
/// <include file='doc\CredentialCache.uex' path='docs/doc[@for="CredentialCache.GetCredential"]/*' /> /// <devdoc> /// <para> /// Returns the <see cref='System.Net.NetworkCredential'/> /// instance associated with the supplied Uri and /// authentication type. /// </para> /// </devdoc> public NetworkCredential GetCredential(Uri uriPrefix, string authType) { if (uriPrefix == null) { throw new ArgumentNullException("asyncResult"); } if (authType == null) { throw new ArgumentNullException("authType"); } GlobalLog.Print("CredentialCache::GetCredential(uriPrefix=\"" + uriPrefix + "\", authType=\"" + authType + "\")"); int longestMatchPrefix = -1; NetworkCredential mostSpecificMatch = null; IDictionaryEnumerator credEnum = cache.GetEnumerator(); // // Enumerate through every credential in the cache // while (credEnum.MoveNext()) { CredentialKey key = (CredentialKey)credEnum.Key; // // Determine if this credential is applicable to the current Uri/AuthType // if (key.Match(uriPrefix, authType)) { int prefixLen = key.UriPrefixLength; // // Check if the match is better than the current-most-specific match // if (prefixLen > longestMatchPrefix) { // // Yes-- update the information about currently preferred match // longestMatchPrefix = prefixLen; mostSpecificMatch = (NetworkCredential)credEnum.Value; } } } GlobalLog.Print("CredentialCache::GetCredential returning " + ((mostSpecificMatch == null)?"null":"(" + mostSpecificMatch.UserName + ":" + mostSpecificMatch.Password + ":" + mostSpecificMatch.Domain + ")")); return(mostSpecificMatch); }
public NetworkCredential?GetCredential(Uri uriPrefix, string authType) { ArgumentNullException.ThrowIfNull(uriPrefix); ArgumentNullException.ThrowIfNull(authType); if (_cache == null) { if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, "CredentialCache::GetCredential short-circuiting because the dictionary is null."); } return(null); } int longestMatchPrefix = -1; NetworkCredential?mostSpecificMatch = null; // Enumerate through every credential in the cache foreach (KeyValuePair <CredentialKey, NetworkCredential> pair in _cache) { CredentialKey key = pair.Key; // Determine if this credential is applicable to the current Uri/AuthType if (key.Match(uriPrefix, authType)) { int prefixLen = key.UriPrefixLength; // Check if the match is better than the current-most-specific match if (prefixLen > longestMatchPrefix) { // Yes: update the information about currently preferred match longestMatchPrefix = prefixLen; mostSpecificMatch = pair.Value; } } } if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(this, $"Returning {(mostSpecificMatch == null ? "null" : "(" + mostSpecificMatch.UserName + ":" + mostSpecificMatch.Domain + ")")}"); } return(mostSpecificMatch); }