CredentialCache Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides storage for multiple credentials.
public ref class CredentialCache : System::Collections::IEnumerable, System::Net::ICredentials, System::Net::ICredentialsByHost
public ref class CredentialCache : System::Collections::IEnumerable, System::Net::ICredentials
public class CredentialCache : System.Collections.IEnumerable, System.Net.ICredentials, System.Net.ICredentialsByHost
public class CredentialCache : System.Collections.IEnumerable, System.Net.ICredentials
type CredentialCache = class
interface IEnumerable
interface ICredentials
interface ICredentialsByHost
type CredentialCache = class
interface ICredentials
interface IEnumerable
type CredentialCache = class
interface ICredentials
interface ICredentialsByHost
interface IEnumerable
Public Class CredentialCache
Implements ICredentials, ICredentialsByHost, IEnumerable
Public Class CredentialCache
Implements ICredentials, IEnumerable
- Inheritance
-
CredentialCache
- Implements
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;
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri("http://www.contoso.com/"),"Basic",new NetworkCredential(UserName,SecurelyStoredPassword));
myCache.Add(new Uri("http://www.contoso.com/"),"Digest", new NetworkCredential(UserName,SecurelyStoredPassword,Domain));
wReq.Credentials = myCache;
Dim myCache As New CredentialCache()
myCache.Add(New Uri("http://www.contoso.com/"), "Basic", New NetworkCredential(UserName, SecurelyStoredPassword))
myCache.Add(New Uri("http://www.contoso.com/"), "Digest", New NetworkCredential(UserName, SecurelyStoredPassword, Domain))
wReq.Credentials = myCache
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.
Credential |
Creates a new instance of the CredentialCache class. |
Default |
Gets the system credentials of the application. |
Default |
Gets the network credentials of the current security context. |
Add(String, Int32, String, Network |
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, Network |
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) |
Get |
Returns the NetworkCredential instance associated with the specified host, port, and authentication protocol. |
Get |
Returns the NetworkCredential instance associated with the specified Uniform Resource Identifier (URI) and authentication type. |
Get |
Returns an enumerator that can iterate through the CredentialCache instance. |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
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. |
To |
Returns a string that represents the current object. (Inherited from Object) |
Cast<TResult>(IEnumerable) |
Casts the elements of an IEnumerable to the specified type. |
Of |
Filters the elements of an IEnumerable based on a specified type. |
As |
Enables parallelization of a query. |
As |
Converts an IEnumerable to an IQueryable. |
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: