NetworkCredential 建構函式

定義

初始化 NetworkCredential 類別的新執行個體。

多載

NetworkCredential()

初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, SecureString)

使用指定的使用者名稱和密碼來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, String)

使用指定的使用者名稱和密碼來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, SecureString, String)

使用指定的使用者名稱、密碼和網域來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential(String, String, String)

使用指定的使用者名稱、密碼和網域來初始化 NetworkCredential 類別的新執行個體。

NetworkCredential()

來源:
NetworkCredential.cs
來源:
NetworkCredential.cs
來源:
NetworkCredential.cs

初始化 NetworkCredential 類別的新執行個體。

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

備註

類別的無參數建構函式會將 NetworkCredential 所有屬性初始化為 null

適用於

NetworkCredential(String, SecureString)

來源:
NetworkCredential.cs
來源:
NetworkCredential.cs
來源:
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 類別在這個平台上不受支援。

備註

建構函式會 NetworkCredential 初始化 物件, UserName 並將 屬性設定 userNamePasswordpassword為 。

參數 passwordSecureString 實例。

如果呼叫這個建構函式並將 password 參數設定為 null,則會初始化 的新實例 SecureString ,如果此平臺不支援安全字串,則會 NotSupportedException 擲回 。

適用於

NetworkCredential(String, String)

來源:
NetworkCredential.cs
來源:
NetworkCredential.cs
來源:
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()

備註

建構函式會 NetworkCredential 初始化 物件, UserName 並將 屬性設定 userNamePasswordpassword為 。

適用於

NetworkCredential(String, SecureString, String)

來源:
NetworkCredential.cs
來源:
NetworkCredential.cs
來源:
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 類別在這個平台上不受支援。

備註

建構函式會將 NetworkCredentialUserName 屬性設定為 userNamePassword 屬性設定為 password,並將屬性設定為 ,並將 Domain 屬性初始化為 domain

參數 passwordSecureString 實例。

如果呼叫這個建構函式並將 password 參數設定為 null,則會初始化 的新實例 SecureString ,如果此平臺不支援安全字串,則會 NotSupportedException 擲回 。

適用於

NetworkCredential(String, String, String)

來源:
NetworkCredential.cs
來源:
NetworkCredential.cs
來源:
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

與這些認證相關的網域。

備註

建構函式會將 NetworkCredentialUserName 屬性設定為 userNamePassword 屬性設定為 password,並將屬性設定為 ,並將 Domain 屬性初始化為 domain

適用於