コード例 #1
0
        /// <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 = this.cacheForHost.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CredentialCache.CredentialCacheForHostKey credentialCacheForHostKey = enumerator.Key as CredentialCache.CredentialCacheForHostKey;
                if (string.Compare(credentialCacheForHostKey.AuthType, authenticationType, true) == 0)
                {
                    if (!(credentialCacheForHostKey.Host != host))
                    {
                        if (credentialCacheForHostKey.Port == port)
                        {
                            result = (NetworkCredential)enumerator.Value;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #2
0
 public override bool Equals(object obj)
 {
     CredentialCache.CredentialCacheForHostKey credentialCacheForHostKey = obj as CredentialCache.CredentialCacheForHostKey;
     return(credentialCacheForHostKey != null && this.hash == credentialCacheForHostKey.hash);
 }