System.Net.CredentialCache.GetCredential Method

Returns the System.Net.NetworkCredential instance associated with the specified Uniform Resource Identifier (URI) and authentication type.

Syntax

public NetworkCredential GetCredential (Uri uriPrefix, string authType)

Parameters

uriPrefix
A Uri that specifies the URI prefix of the resources that the credential grants access to.
authType
The authentication scheme used by the resource named in uriPrefix.

Returns

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

Exceptions

TypeReason
ArgumentNullExceptionThe uriPrefix or authType parameter is null.

Remarks

The CredentialCache.GetCredential(Uri, string) method searches the System.Net.CredentialCache and returns the System.Net.NetworkCredential instance for the specified URI and authorization type. If the System.Net.CredentialCache contains no matching System.Net.NetworkCredential instance, null is returned.

CredentialCache.GetCredential(Uri, string) uses the longest matching URI prefix in the cache to determine which set of credentials to return for an authorization type. The following table shows examples.

http://www.contoso.com/portal/news.htm

Requests for the specific Web page news.htm.

http://www.contoso.com/portal/

Requests for all content in the portal path, except the page news.htm.

http://www.contoso.com/

Requests for all resources at www.contoso.com, except those in the portal path.

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0