NetworkCredential NetworkCredential NetworkCredential NetworkCredential Constructors

Definition

Overloads

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

NetworkCredential() NetworkCredential() NetworkCredential()

Initializes a new instance of the NetworkCredential class.

public:
 NetworkCredential();
public NetworkCredential ();
Public Sub New ()

Remarks

The default constructor for the NetworkCredential class initializes all properties to null.

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

Important

This API is not CLS-compliant.

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

public:
 NetworkCredential(System::String ^ userName, System::Security::SecureString ^ password);
[System.CLSCompliant(false)]
public NetworkCredential (string userName, System.Security.SecureString password);
new System.Net.NetworkCredential : string * System.Security.SecureString -> System.Net.NetworkCredential
Public Sub New (userName As String, password As SecureString)
Parameters
userName
String String String String

The user name associated with the credentials.

password
SecureString SecureString SecureString SecureString

The password for the user name associated with the credentials.

Exceptions

Remarks

The constructor initializes a NetworkCredential object with the UserName property set to userName and the Password property set to password.

The password parameter is a SecureString instance.

If this constructor is called with the password parameter set to null, a new instance of SecureString is initialized, If secure strings are not supported on this platform, then the NotSupportedException is thrown

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.

public:
 NetworkCredential(System::String ^ userName, System::String ^ password);
public NetworkCredential (string userName, string password);
new System.Net.NetworkCredential : string * string -> System.Net.NetworkCredential
Public Sub New (userName As String, password As String)
Parameters
userName
String String String String

The user name associated with the credentials.

password
String String String String

The password for the user name associated with the credentials.

Examples

The following code example creates a NetworkCredential object using the specified user name and password.

// Call the onstructor  to create an instance of NetworkCredential with the
// specified user name and password.
NetworkCredential^ myCredentials = gcnew NetworkCredential( username,passwd );

// Create a WebRequest with the specified URL.
WebRequest^ myWebRequest = WebRequest::Create( url );
myCredentials->Domain = domain;
myWebRequest->Credentials = myCredentials;
Console::WriteLine( "\n\nCredentials Domain : {0} , UserName : {1} , Password : {2}",
   myCredentials->Domain, myCredentials->UserName, myCredentials->Password );
Console::WriteLine( "\n\nRequest to Url is sent.Waiting for response..." );

// Send the request and wait for a response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Process the response.
Console::WriteLine( "\nResponse received successfully." );

// Release the resources of the response object.
myWebResponse->Close();
 // Call the onstructor  to create an instance of NetworkCredential with the 
 // specified user name and password.
 NetworkCredential myCredentials = new NetworkCredential(username,passwd);

// Create a WebRequest with the specified URL. 
WebRequest myWebRequest = WebRequest.Create(url);
myCredentials.Domain = domain;
myWebRequest.Credentials = myCredentials;
Console.WriteLine("\n\nCredentials Domain : {0} , UserName : {1} , Password : {2}",
myCredentials.Domain, myCredentials.UserName, myCredentials.Password);
Console.WriteLine("\n\nRequest to Url is sent.Waiting for response...");


// Send the request and wait for a response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Process the response.
Console.WriteLine("\nResponse received successfully.");
// Release the resources of the response object.
myWebResponse.Close();
' Call the constructor  to create an instance of NetworkCredential with the
' specified user name and password.
Dim myCredentials As New NetworkCredential(username, passwd)
' Create a WebRequest with the specified URL. 
Dim myWebRequest As WebRequest = WebRequest.Create(url)
myCredentials.Domain = domain
myWebRequest.Credentials = myCredentials
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Credentials Domain : {0} , UserName : {1} , Password : {2}", myCredentials.Domain, myCredentials.UserName, myCredentials.Password)
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Request to Url is sent.Waiting for response...")
' Send the request and wait for a response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Process the response.
Console.WriteLine(ControlChars.Cr + "Response received successfully.")
' Release the resources of the response object.
myWebResponse.Close()

Remarks

The constructor initializes a NetworkCredential object with the UserName property set to userName and the Password property set to password.

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

Important

This API is not CLS-compliant.

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

public:
 NetworkCredential(System::String ^ userName, System::Security::SecureString ^ password, System::String ^ domain);
[System.CLSCompliant(false)]
public NetworkCredential (string userName, System.Security.SecureString password, string domain);
new System.Net.NetworkCredential : string * System.Security.SecureString * string -> System.Net.NetworkCredential
Public Sub New (userName As String, password As SecureString, domain As String)
Parameters
userName
String String String String

The user name associated with the credentials.

password
SecureString SecureString SecureString SecureString

The password for the user name associated with the credentials.

domain
String String String String

The domain associated with these credentials.

Exceptions

Remarks

The constructor initializes a NetworkCredential object with the UserName property set to userName, the Password property set to password, and the Domain property set to domain.

The password parameter is a SecureString instance.

If this constructor is called with the password parameter set to null, a new instance of SecureString is initialized, If secure strings are not supported on this platform, then the NotSupportedException is thrown

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.

public:
 NetworkCredential(System::String ^ userName, System::String ^ password, System::String ^ domain);
public NetworkCredential (string userName, string password, string domain);
new System.Net.NetworkCredential : string * string * string -> System.Net.NetworkCredential
Public Sub New (userName As String, password As String, domain As String)
Parameters
userName
String String String String

The user name associated with the credentials.

password
String String String String

The password for the user name associated with the credentials.

domain
String String String String

The domain associated with these credentials.

Remarks

The constructor initializes a NetworkCredential object with the UserName property set to userName, the Password property set to password, and the Domain property set to domain.

Applies to