System.Net.CredentialCache Class

public class CredentialCache : ICredentials, IEnumerable

Base Types

Object
  CredentialCache

This type implements ICredentials and IEnumerable.

Assembly

System

Library

Networking

Summary

Provides storage for multiple credentials.

Description

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.

See Also

System.Net Namespace

Members

CredentialCache Constructors

CredentialCache Constructor

CredentialCache Methods

CredentialCache.Add Method
CredentialCache.GetCredential Method
CredentialCache.GetEnumerator Method
CredentialCache.Remove Method

CredentialCache Properties

CredentialCache.DefaultCredentials Property


CredentialCache Constructor

public CredentialCache();

Summary

Constructs and initializes a new instance of the CredentialCache class.

Description

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. ]

See Also

System.Net.CredentialCache Class, System.Net Namespace

CredentialCache.Add Method

public void Add(Uri uriPrefix, string authType, NetworkCredential cred);

Summary

Adds a NetworkCredential instance to the credential cache.

Parameters

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.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThe uriPrefix or authType parameter is null .
ArgumentExceptionThe cache already contains a credential for the specified uriPrefix and authType.

Description

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.]

See Also

System.Net.CredentialCache Class, System.Net Namespace

CredentialCache.GetCredential Method

public NetworkCredential GetCredential(Uri uriPrefix, string authType);

Summary

Returns the NetworkCredential instance associated with a URI and authentication type.

Parameters

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.

Return Value

A NetworkCredential, or null if there is no matching credential in the cache.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThe uriPrefix or authType parameter is null .

Description

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 PrefixMatches
http://www.contoso.com/portal/news.htmMatches 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.
]

See Also

System.Net.CredentialCache Class, System.Net Namespace

CredentialCache.GetEnumerator Method

public IEnumerator GetEnumerator();

Summary

Returns an enumerator that iterates through credentials stored in the current CredentialCache instance.

Return Value

A IEnumerator for the current CredentialCache instance.

See Also

System.Net.CredentialCache Class, System.Net Namespace

CredentialCache.Remove Method

public void Remove(Uri uriPrefix, string authType);

Summary

Deletes a NetworkCredential instance from the cache.

Parameters

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.

Description

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).]

See Also

System.Net.CredentialCache Class, System.Net Namespace

CredentialCache.DefaultCredentials Property

public static ICredentials DefaultCredentials { get; }

Summary

Gets the system credentials in use for the current process.

Property Value

A ICredentials instance that represents the system credentials in use for the current process.

Description

This property is read-only.

See Also

System.Net.CredentialCache Class, System.Net Namespace