CredentialCache Class
Provides storage for multiple credentials.
Assembly: System (in System.dll)
| Name | Description | |
|---|---|---|
![]() | CredentialCache() | Creates a new instance of the CredentialCache class. |
| Name | Description | |
|---|---|---|
![]() ![]() | DefaultCredentials | Gets the system credentials of the application. |
![]() ![]() | DefaultNetworkCredentials | Gets the network credentials of the current security context. |
| Name | Description | |
|---|---|---|
![]() | Add(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. |
![]() | Add(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. |
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetCredential(String^, Int32, String^) | Returns the NetworkCredential instance associated with the specified host, port, and authentication protocol. |
![]() | GetCredential(Uri^, String^) | Returns the NetworkCredential instance associated with the specified Uniform Resource Identifier (URI) and authentication type. |
![]() | GetEnumerator() | Returns an enumerator that can iterate through the CredentialCache instance. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | Remove(String^, Int32, String^) | Deletes a NetworkCredential instance from the cache if it is associated with the specified host, port, and authentication protocol. |
![]() | Remove(Uri^, String^) | Deletes a NetworkCredential instance from the cache if it is associated with the specified Uniform Resource Identifier (URI) prefix and authentication protocol. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | AsParallel() | Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.) |
![]() | AsQueryable() | Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.) |
![]() | Cast<TResult>() | Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.) |
![]() | OfType<TResult>() | Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.) |
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;
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.1
Windows Phone
Available since 8.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.



