public NetworkCredential GetCredential(string host, int port, string authenticationType) { NetworkCredential result = null; if (host == null || port < 0 || authenticationType == null) { return(null); } IDictionaryEnumerator e = cacheForHost.GetEnumerator(); while (e.MoveNext()) { CredentialCacheForHostKey key = e.Key as CredentialCacheForHostKey; if (String.Compare(key.AuthType, authenticationType, true) != 0) { continue; } if (key.Host != host) { continue; } if (key.Port != port) { continue; } result = (NetworkCredential)e.Value; } return(result); }
/// <summary>Returns the <see cref="T:System.Net.NetworkCredential" /> instance associated with the specified host, port, and authentication protocol.</summary> /// <returns>A <see cref="T:System.Net.NetworkCredential" /> or, if there is no matching credential in the cache, null.</returns> /// <param name="host">A <see cref="T:System.String" /> that identifies the host computer.</param> /// <param name="port">A <see cref="T:System.Int32" /> that specifies the port to connect to on <paramref name="host" />.</param> /// <param name="authenticationType">A <see cref="T:System.String" /> that identifies the authentication scheme used when connecting to <paramref name="host" />. See Remarks.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="host" /> is null. -or- <paramref name="authType" /> is null. </exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="authType" /> not an accepted value. See Remarks. -or-<paramref name="host" /> is equal to the empty string ("").</exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="port" /> is less than zero.</exception> public NetworkCredential GetCredential(string host, int port, string authenticationType) { NetworkCredential result = null; if (host == null || port < 0 || authenticationType == null) { return(null); } IDictionaryEnumerator enumerator = cacheForHost.GetEnumerator(); while (enumerator.MoveNext()) { CredentialCacheForHostKey credentialCacheForHostKey = enumerator.Key as CredentialCacheForHostKey; if (string.Compare(credentialCacheForHostKey.AuthType, authenticationType, ignoreCase: true) == 0 && !(credentialCacheForHostKey.Host != host) && credentialCacheForHostKey.Port == port) { result = (NetworkCredential)enumerator.Value; } } return(result); }
public override bool Equals(object obj) { CredentialCacheForHostKey key = obj as CredentialCacheForHostKey; return((key != null) && (this.hash == key.hash)); }
public override bool Equals(object obj) { CredentialCacheForHostKey credentialCacheForHostKey = obj as CredentialCacheForHostKey; return(credentialCacheForHostKey != null && hash == credentialCacheForHostKey.hash); }