Export (0) Print
Expand All

CredentialCache Class

Provides storage for multiple credentials.

System::Object
  System.Net::CredentialCache

Namespace:  System.Net
Assembly:  System (in System.dll)

public ref class CredentialCache : ICredentials, 
	ICredentialsByHost, IEnumerable

The CredentialCache type exposes the following members.

  NameDescription
Public methodSupported in .NET for Windows Store appsCredentialCacheCreates a new instance of the CredentialCache class.
Top

  NameDescription
Public propertyStatic memberSupported in .NET for Windows Store appsDefaultCredentialsGets the system credentials of the application.
Public propertyStatic memberSupported in .NET for Windows Store appsDefaultNetworkCredentialsGets the network credentials of the current security context.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsAdd(Uri, String, NetworkCredential)Adds a NetworkCredential instance to the credential cache for use with protocols other than SMTP and associates it with a Uniform Resource Identifier (URI) prefix and authentication protocol.
Public methodSupported in .NET for Windows Store appsAdd(String, Int32, String, NetworkCredential)Adds a NetworkCredential instance for use with SMTP to the credential cache and associates it with a host computer, port, and authentication protocol. Credentials added using this method are valid for SMTP only. This method does not work for HTTP or FTP requests.
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetCredential(Uri, String)Returns the NetworkCredential instance associated with the specified Uniform Resource Identifier (URI) and authentication type.
Public methodSupported in .NET for Windows Store appsGetCredential(String, Int32, String)Returns the NetworkCredential instance associated with the specified host, port, and authentication protocol.
Public methodSupported in .NET for Windows Store appsGetEnumeratorReturns an enumerator that can iterate through the CredentialCache instance.
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsRemove(Uri, String)Deletes a NetworkCredential instance from the cache if it is associated with the specified Uniform Resource Identifier (URI) prefix and authentication protocol.
Public methodSupported in .NET for Windows Store appsRemove(String, Int32, String)Deletes a NetworkCredential instance from the cache if it is associated with the specified host, port, and authentication protocol.
Public methodSupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodSupported in .NET for Windows Store appsAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodSupported in .NET for Windows Store appsAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported in .NET for Windows Store appsCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported in .NET for Windows Store appsOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

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 to the Internet resource when required. When the GetCredential method is called, it compares the Uniform Resource Identifier (URI) and authentication type provided with those stored in the cache and returns the first set of credentials that match.

The DefaultCredentials property contains the system credentials of the current security context. For client applications, these represent the user name, password, and domain of the user who is currently logged in. For ASP.NET applications, the default credentials are the user credentials of the logged-in user or the user being impersonated.

The following code example initializes a CredentialCache with multiple security credentials and uses those credentials with a WebRequest.

CredentialCache^ myCache = gcnew CredentialCache;

myCache->Add( gcnew Uri( "http://www.contoso.com/" ), "Basic", gcnew NetworkCredential( UserName,SecurelyStoredPassword ) );
myCache->Add( gcnew Uri( "http://www.contoso.com/" ), "Digest", gcnew NetworkCredential( UserName,SecurelyStoredPassword,Domain ) );

wReq->Credentials = myCache;

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft