NetworkCredential 构造函数

定义

初始化 NetworkCredential 类的新实例。

重载

NetworkCredential()

初始化 NetworkCredential 类的新实例。

NetworkCredential(String, SecureString)

用指定的用户名和密码初始化 NetworkCredential 类的新实例。

NetworkCredential(String, String)

用指定的用户名和密码初始化 NetworkCredential 类的新实例。

NetworkCredential(String, SecureString, String)

用指定的用户名、密码和域初始化 NetworkCredential 类的新实例。

NetworkCredential(String, String, String)

用指定的用户名、密码和域初始化 NetworkCredential 类的新实例。

NetworkCredential()

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

初始化 NetworkCredential 类的新实例。

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

注解

类的 NetworkCredential 无参数构造函数将所有属性初始化为 null

适用于

NetworkCredential(String, SecureString)

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

重要

此 API 不符合 CLS。

用指定的用户名和密码初始化 NetworkCredential 类的新实例。

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)

参数

userName
String

与凭据关联的用户名。

password
SecureString

与凭据关联的用户名的密码。

属性

例外

SecureString 在此平台上不受支持。

注解

构造函数初始化对象 NetworkCredentialUserName 其中属性设置为 userNamePassword 属性设置为 password

参数 password 是实例 SecureString

如果调用此构造函数并将 password 参数设置为 null,则会初始化 的新 SecureString 实例;如果此平台上不支持安全字符串,则会 NotSupportedException 引发

适用于

NetworkCredential(String, String)

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

用指定的用户名和密码初始化 NetworkCredential 类的新实例。

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)

参数

userName
String

与凭据关联的用户名。

password
String

与凭据关联的用户名的密码。

示例

下面的代码示例使用指定的用户名和密码创建对象 NetworkCredential

// 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()

注解

构造函数初始化对象 NetworkCredentialUserName 其中属性设置为 userNamePassword 属性设置为 password

适用于

NetworkCredential(String, SecureString, String)

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

重要

此 API 不符合 CLS。

用指定的用户名、密码和域初始化 NetworkCredential 类的新实例。

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)

参数

userName
String

与凭据关联的用户名。

password
SecureString

与凭据关联的用户名的密码。

domain
String

与这些凭据关联的域。

属性

例外

SecureString 在此平台上不受支持。

注解

构造函数初始化 一个 NetworkCredential 对象, UserName 其中属性设置为 userNamePassword 属性设置为 passwordDomain 属性设置为 domain

参数 password 是实例 SecureString

如果调用此构造函数并将 password 参数设置为 null,则会初始化 的新 SecureString 实例;如果此平台上不支持安全字符串,则会 NotSupportedException 引发

适用于

NetworkCredential(String, String, String)

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

用指定的用户名、密码和域初始化 NetworkCredential 类的新实例。

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)

参数

userName
String

与凭据关联的用户名。

password
String

与凭据关联的用户名的密码。

domain
String

与这些凭据关联的域。

注解

构造函数初始化 一个 NetworkCredential 对象, UserName 其中属性设置为 userNamePassword 属性设置为 passwordDomain 属性设置为 domain

适用于