Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
NetworkCredential Class

NetworkCredential Class

Provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.

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


[Visual Basic]
Public Class NetworkCredential
   Implements ICredentials
public class NetworkCredential : ICredentials
public __gc class NetworkCredential : public ICredentials
public class NetworkCredential implements ICredentials

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.


The NetworkCredential class is a base class that supplies credentials in password-based authentication schemes such as basic, digest, NTLM, and Kerberos. Classes that implement the ICredentials interface, such as the CredentialCache class, return NetworkCredential instances.

This class does not support public key-based authentication methods such as SSL client authentication.


The following example associates a NetworkCredential instance with a set of Uniform Resource Identifiers (URIs) in a CredentialCache. It then passes the CredentialCache to a WebRequest instance, which uses it to authenticate requests to an Internet server.

[Visual Basic] 
Dim myCred As New NetworkCredential(SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain )
Dim myCache As New CredentialCache()
myCache.Add(New Uri("www.contoso.com"), "Basic", myCred)
myCache.Add(New Uri("app.contoso.com"), "Basic", myCred)
Dim wr As WebRequest = WebRequest.Create("www.contoso.com")
wr.Credentials = myCache

NetworkCredential myCred = new NetworkCredential(
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri("www.contoso.com"), "Basic", myCred);
myCache.Add(new Uri("app.contoso.com"), "Basic", myCred);
WebRequest wr = WebRequest.Create("www.contoso.com");
wr.Credentials = myCache;

NetworkCredential* myCred = new NetworkCredential(
CredentialCache* myCache = new CredentialCache();
myCache->Add(new Uri(S"www.contoso.com"), S"Basic", myCred);
myCache->Add(new Uri(S"app.contoso.com"), S"Basic", myCred);
WebRequest* wr = WebRequest::Create(S"www.contoso.com");
wr->Credentials = myCache;

var myCred : NetworkCredential = new NetworkCredential(
   SecurelyStoredUserName, SecurelyStoredPassword, SecurelyStoredDomain )
var myCache : CredentialCache = new CredentialCache()
myCache.Add(new Uri("www.contoso.com"), "Basic", myCred)
myCache.Add(new Uri("app.contoso.com"), "Basic", myCred)
var wr : WebRequest = WebRequest.Create("www.contoso.com")
wr.Credentials = myCache


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, .NET Compact Framework

Assembly: System (in System.dll)

See Also

NetworkCredential Members | System.Net Namespace

© 2015 Microsoft