public class CredentialCache : ICredentials, IEnumerable
Object
CredentialCacheThis type implements ICredentials and IEnumerable.
System
Networking
Provides storage for multiple credentials.
The CredentialCache class stores credentials for multiple Internet resources. Applications that need to access multiple resources can store the credentials for those resources in a CredentialCache instance that then provides the proper set of credentials for a given resource when required. When the System.Net.CredentialCache.GetCredential(System.Uri,System.String) method is called, it compares the URI and authentication type provided with those stored in the cache, and returns the first set of credentials that match.
System.Net Namespace
CredentialCache Constructors
CredentialCache Methods
CredentialCache.Add Method
CredentialCache.GetCredential Method
CredentialCache.GetEnumerator Method
CredentialCache.Remove Method
CredentialCache Properties
public CredentialCache();
Constructs and initializes a new instance of the CredentialCache class.
This constructor creates a CredentialCache instance with its System.Net.CredentialCache.DefaultCredentials property initialized to the system credentials of the current process.[Note: Use the System.Net.CredentialCache.Add(System.Uri,System.String,System.Net.NetworkCredential) method to add additional credentials to the CredentialCache instance. ]
System.Net.CredentialCache Class, System.Net Namespace
public void Add(Uri uriPrefix, string authType, NetworkCredential cred);
Adds a NetworkCredential instance to the credential cache.
- uriPrefix
- A Uri that contains the URI prefix of resources to which cred grants access.
- authType
- A String containing the authentication type used by the resource named in uriPrefix . This string is required to be identical to the System.Net.IAuthenticationModule.AuthenticationType of the authentication module that uses the credential.
- cred
- A NetworkCredential to add to the credential cache.
Exception Type Condition ArgumentNullException The uriPrefix or authType parameter is null
.ArgumentException The cache already contains a credential for the specified uriPrefix and authType.
The cache stores credentials in the order in which they are added.[Note: Use the System.Net.CredentialCache.GetCredential(System.Uri,System.String) method to retrieve NetworkCredential instances.]
System.Net.CredentialCache Class, System.Net Namespace
public NetworkCredential GetCredential(Uri uriPrefix, string authType);
Returns the NetworkCredential instance associated with a URI and authentication type.
- uriPrefix
- A Uri that contains the URI prefix of resources for which the client will be authenticated.
- authType
- A String containing the authentication type used by the resource named in uriPrefix . This string is required to be identical to the System.Net.IAuthenticationModule.AuthenticationType of the authentication module that uses the credential.
A NetworkCredential, ornull
if there is no matching credential in the cache.
Exception Type Condition ArgumentNullException The uriPrefix or authType parameter is null
.
This method searches the CredentialCache and returns the NetworkCredential instance for the specified URI prefix and authentication type. This method uses the longest matching URI prefix in the cache to determine which credentials to return for an authentication type.[Note: The following table shows the matches for a set of URI prefixes (assuming the URI prefixes are all cached for the specified authentication type).
]
URI Prefix Matches http://www.contoso.com/portal/news.htm Matches only requests for http://www.contoso.com/portal/news.htm. http://www.contoso.com/portal/ Matches requests for all resources in the portal path, except for requests for the http://www.contoso.com/portal/news.htm page. http://www.contoso.com/ Matches requests for all resources at www.contoso.com, except those in the portal path.
System.Net.CredentialCache Class, System.Net Namespace
public IEnumerator GetEnumerator();
Returns an enumerator that iterates through credentials stored in the current CredentialCache instance.
A IEnumerator for the current CredentialCache instance.
System.Net.CredentialCache Class, System.Net Namespace
public void Remove(Uri uriPrefix, string authType);
Deletes a NetworkCredential instance from the cache.
- uriPrefix
- A Uri that specifies the resources for which the credential is used.
- authType
- A String containing the authentication type used by the resource named in uriPrefix . This string is required to be identical to the System.Net.IAuthenticationModule.AuthenticationType of the authentication module that uses the credential.
The System.Net.CredentialCache.Remove(System.Uri,System.String) method locates and removes the NetworkCredential instance that is cached for the specified URI prefix and authentication type. If there is no match found in the cache for the specified values, this method has no effect. The uriPrefix and authType values are required to exactly match the values supplied at the time the credential was added to the cache. [Note: For additional information, see System.Net.CredentialCache.Add(System.Uri,System.String,System.Net.NetworkCredential).]
System.Net.CredentialCache Class, System.Net Namespace
public static ICredentials DefaultCredentials { get; }
Gets the system credentials in use for the current process.
A ICredentials instance that represents the system credentials in use for the current process.
This property is read-only.
System.Net.CredentialCache Class, System.Net Namespace