Rediger

Del via


NetworkCredential Constructors

Definition

Initializes a new instance of the NetworkCredential class.

Overloads

NetworkCredential()

Initializes a new instance of the NetworkCredential class.

NetworkCredential(String, SecureString)

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

NetworkCredential(String, String)

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

NetworkCredential(String, SecureString, String)

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

NetworkCredential(String, String, String)

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

NetworkCredential()

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

Initializes a new instance of the NetworkCredential class.

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

Remarks

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

Applies to

NetworkCredential(String, SecureString)

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

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);
[System.CLSCompliant(false)]
public NetworkCredential (string userName, System.Security.SecureString password);
public NetworkCredential (string userName, System.Security.SecureString password);
[<System.CLSCompliant(false)>]
new System.Net.NetworkCredential : string * System.Security.SecureString -> System.Net.NetworkCredential
new System.Net.NetworkCredential : string * System.Security.SecureString -> System.Net.NetworkCredential
Public Sub New (userName As String, password As SecureString)

Parameters

userName
String

The user name associated with the credentials.

password
SecureString

The password for the user name associated with the credentials.

Attributes

Exceptions

The SecureString class is not supported on this platform.

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

Applies to

NetworkCredential(String, String)

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

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);
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

The user name associated with the credentials.

password
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 constructor 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.

Applies to

NetworkCredential(String, SecureString, String)

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

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);
[System.CLSCompliant(false)]
public NetworkCredential (string userName, System.Security.SecureString password, string domain);
public NetworkCredential (string userName, System.Security.SecureString password, string domain);
[<System.CLSCompliant(false)>]
new System.Net.NetworkCredential : string * System.Security.SecureString * string -> System.Net.NetworkCredential
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

The user name associated with the credentials.

password
SecureString

The password for the user name associated with the credentials.

domain
String

The domain associated with these credentials.

Attributes

Exceptions

The SecureString class is not supported on this platform.

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

Applies to

NetworkCredential(String, String, String)

Source:
NetworkCredential.cs
Source:
NetworkCredential.cs
Source:
NetworkCredential.cs

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);
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

The user name associated with the credentials.

password
String

The password for the user name associated with the credentials.

domain
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