NetworkCredential Constructors
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the NetworkCredential class.
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. |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
- 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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: