コード例 #1
0
        /// <summary>Returns the <see cref="T:System.Net.NetworkCredential" /> instance associated with the specified Uniform Resource Identifier (URI) and authentication type.</summary>
        /// <returns>A <see cref="T:System.Net.NetworkCredential" /> or, if there is no matching credential in the cache, null.</returns>
        /// <param name="uriPrefix">A <see cref="T:System.Uri" /> that specifies the URI prefix of the resources that the credential grants access to. </param>
        /// <param name="authType">The authentication scheme used by the resource named in <paramref name="uriPrefix" />. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="uriPrefix" /> or <paramref name="authType" /> is null. </exception>
        public NetworkCredential GetCredential(System.Uri uriPrefix, string authType)
        {
            int num = -1;
            NetworkCredential result = null;

            if (uriPrefix == null || authType == null)
            {
                return(null);
            }
            string text = uriPrefix.AbsolutePath;

            text = text.Substring(0, text.LastIndexOf('/'));
            IDictionaryEnumerator enumerator = this.cache.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CredentialCache.CredentialCacheKey credentialCacheKey = enumerator.Key as CredentialCache.CredentialCacheKey;
                if (credentialCacheKey.Length > num)
                {
                    if (string.Compare(credentialCacheKey.AuthType, authType, true) == 0)
                    {
                        System.Uri uriPrefix2 = credentialCacheKey.UriPrefix;
                        if (!(uriPrefix2.Scheme != uriPrefix.Scheme))
                        {
                            if (uriPrefix2.Port == uriPrefix.Port)
                            {
                                if (!(uriPrefix2.Host != uriPrefix.Host))
                                {
                                    if (text.StartsWith(credentialCacheKey.AbsPath))
                                    {
                                        num    = credentialCacheKey.Length;
                                        result = (NetworkCredential)enumerator.Value;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
コード例 #2
0
 public override bool Equals(object obj)
 {
     CredentialCache.CredentialCacheKey credentialCacheKey = obj as CredentialCache.CredentialCacheKey;
     return(credentialCacheKey != null && this.hash == credentialCacheKey.hash);
 }