NetworkCredential NetworkCredential NetworkCredential NetworkCredential Class

Definition

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

public ref class NetworkCredential : System::Net::ICredentials, System::Net::ICredentialsByHost
public class NetworkCredential : System.Net.ICredentials, System.Net.ICredentialsByHost
type NetworkCredential = class
    interface ICredentials
    interface ICredentialsByHost
Public Class NetworkCredential
Implements ICredentials, ICredentialsByHost
Inheritance
NetworkCredentialNetworkCredentialNetworkCredentialNetworkCredential
Implements

Examples

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.

NetworkCredential^ myCred = gcnew NetworkCredential(
   SecurelyStoredUserName,SecurelyStoredPassword,SecurelyStoredDomain );

CredentialCache^ myCache = gcnew CredentialCache;

myCache->Add( gcnew Uri( "www.contoso.com" ), "Basic", myCred );
myCache->Add( gcnew Uri( "app.contoso.com" ), "Basic", myCred );

WebRequest^ wr = 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.Credentials = myCache;

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

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

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

Constructors

NetworkCredential() NetworkCredential() NetworkCredential() NetworkCredential()

Initializes a new instance of the NetworkCredential class.

NetworkCredential(String, SecureString) NetworkCredential(String, SecureString) NetworkCredential(String, SecureString) NetworkCredential(String, SecureString)

Initializes a new instance of the NetworkCredential class with the specified user name and password.

NetworkCredential(String, SecureString, String) NetworkCredential(String, SecureString, String) NetworkCredential(String, SecureString, String) NetworkCredential(String, SecureString, String)

Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.

NetworkCredential(String, String) NetworkCredential(String, String) NetworkCredential(String, String) NetworkCredential(String, String)

Initializes a new instance of the NetworkCredential class with the specified user name and password.

NetworkCredential(String, String, String) NetworkCredential(String, String, String) NetworkCredential(String, String, String) NetworkCredential(String, String, String)

Initializes a new instance of the NetworkCredential class with the specified user name, password, and domain.

Properties

Domain Domain Domain Domain

Gets or sets the domain or computer name that verifies the credentials.

Password Password Password Password

Gets or sets the password for the user name associated with the credentials.

SecurePassword SecurePassword SecurePassword SecurePassword

Gets or sets the password as a SecureString instance.

UserName UserName UserName UserName

Gets or sets the user name associated with the credentials.

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetCredential(String, Int32, String) GetCredential(String, Int32, String) GetCredential(String, Int32, String) GetCredential(String, Int32, String)

Returns an instance of the NetworkCredential class for the specified host, port, and authentication type.

GetCredential(Uri, String) GetCredential(Uri, String) GetCredential(Uri, String) GetCredential(Uri, String)

Returns an instance of the NetworkCredential class for the specified Uniform Resource Identifier (URI) and authentication type.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to