Export (0) Print
Expand All

NetworkCredential Class

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

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

'Declaration
Public Class NetworkCredential
	Implements ICredentials, ICredentialsByHost
'Usage
Dim instance As NetworkCredential

public class NetworkCredential implements ICredentials, ICredentialsByHost
public class NetworkCredential implements ICredentials, ICredentialsByHost
Not applicable.

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

This class does not support public key-based authentication methods such as Secure Sockets Layer (SSL) client authentication.

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

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(securelyStoredUserName,
    securelyStoredPassword,securelyStoredDomain);
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.set_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


System.Object
  System.Net.NetworkCredential

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft