Export (0) Print
Expand All

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.

System.Object
   System.Net.NetworkCredential

[Visual Basic]
Public Class NetworkCredential
   Implements ICredentials
[C#]
public class NetworkCredential : ICredentials
[C++]
public __gc class NetworkCredential : public ICredentials
[JScript]
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.

Remarks

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.

Example

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


[C#] 
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.Credentials = myCache;


[C++] 
NetworkCredential* myCred = new NetworkCredential(
    SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain);
 
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;


[JScript] 
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

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

Assembly: System (in System.dll)

See Also

NetworkCredential Members | System.Net Namespace

Show:
© 2014 Microsoft