Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

CredentialCache Class

Provides storage for multiple credentials.

For a list of all members of this type, see CredentialCache Members.

System.Object
   System.Net.CredentialCache

[Visual Basic]
Public Class CredentialCache
   Implements ICredentials, IEnumerable
[C#]
public class CredentialCache : ICredentials, IEnumerable
[C++]
public __gc class CredentialCache : public ICredentials,
   IEnumerable
[JScript]
public class CredentialCache implements ICredentials, IEnumerable

Thread Safety

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

Remarks

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

Example

[Visual Basic, C#, C++] The following example initializes a CredentialCache with multiple security credentials and uses those credentials with a WebRequest:

[Visual Basic] 
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

[C#] 
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;

[C++] 
CredentialCache* myCache = new CredentialCache();

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

wReq->Credentials = myCache;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Net

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CredentialCache Members | System.Net Namespace | ICredentials | WebRequest.Credentials

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.