NegotiateStream.AuthenticateAsClientAsync 方法

定義

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。

多載

AuthenticateAsClientAsync()

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。

AuthenticateAsClientAsync(NetworkCredential, String)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的用戶端認證。

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的用戶端認證和通道繫結。

AuthenticateAsClientAsync(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的認證和驗證選項。

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的認證、驗證選項和通道繫結。

AuthenticateAsClientAsync()

來源:
NegotiateStream.cs
來源:
NegotiateStream.cs
來源:
NegotiateStream.cs

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync();
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync ();
abstract member AuthenticateAsClientAsync : unit -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : unit -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync () As Task

傳回

工作物件,表示非同步作業。

例外狀況

驗證失敗。 您可以使用這個物件重試驗證。

驗證失敗。 您可以使用這個物件重試驗證。

此物件已關閉。

已經進行驗證。

-或-

這個資料流先前是用來以伺服器的身分嘗試驗證。 您不能使用資料流以用戶端身分重試驗證。

備註

驗證會使用用戶端的 DefaultCredentials。 未為伺服器指定任何服務主體名稱 (SPN) 。 模擬層級為 Identification,安全性層級為 EncryptAndSign,而且會要求相互驗證。 類別 NegotiateStream 會建構用於相互驗證的SPN。

驗證成功時,您必須檢查 IsEncryptedIsSigned 屬性,以判斷 所使用的 NegotiateStream安全性服務。 IsMutuallyAuthenticated檢查 屬性,以判斷是否發生相互驗證。

如果驗證失敗,您會收到 AuthenticationExceptionInvalidCredentialException。 在此情況下,您可以使用不同的認證重試驗證。

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 AuthenticateAsClient()例外狀況。

適用於

AuthenticateAsClientAsync(NetworkCredential, String)

來源:
NegotiateStream.cs
來源:
NegotiateStream.cs
來源:
NegotiateStream.cs

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的用戶端認證。

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::Net::NetworkCredential ^ credential, System::String ^ targetName);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.NetworkCredential credential, string targetName);
abstract member AuthenticateAsClientAsync : System.Net.NetworkCredential * string -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : System.Net.NetworkCredential * string -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (credential As NetworkCredential, targetName As String) As Task

參數

credential
NetworkCredential

建立用戶端識別所用的 NetworkCredential

targetName
String

服務主要名稱 (SPN),用來唯一識別要驗證的伺服器。

傳回

工作物件,表示非同步作業。

例外狀況

驗證失敗。 您可以使用這個物件重試驗證。

驗證失敗。 您可以使用這個物件重試驗證。

此物件已關閉。

已經進行驗證。

-或-

這個資料流先前是用來以伺服器的身分嘗試驗證。 您不能使用資料流以用戶端身分重試驗證。

targetNamenull

備註

模擬層級為 Identification,安全性層級為 EncryptAndSign,而且會要求相互驗證。 類別 NegotiateStream 會建構用於相互驗證的SPN。

驗證成功時,您必須檢查 IsEncryptedIsSigned 屬性,以判斷 所使用的 NegotiateStream安全性服務。 IsMutuallyAuthenticated檢查 屬性,以判斷是否發生相互驗證。

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 AuthenticateAsClient(NetworkCredential, String)例外狀況。

適用於

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String)

來源:
NegotiateStream.cs
來源:
NegotiateStream.cs
來源:
NegotiateStream.cs

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的用戶端認證和通道繫結。

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::Net::NetworkCredential ^ credential, System::Security::Authentication::ExtendedProtection::ChannelBinding ^ binding, System::String ^ targetName);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding? binding, string targetName);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding binding, string targetName);
abstract member AuthenticateAsClientAsync : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (credential As NetworkCredential, binding As ChannelBinding, targetName As String) As Task

參數

credential
NetworkCredential

建立用戶端識別所用的 NetworkCredential

binding
ChannelBinding

用於延伸保護的 ChannelBinding

targetName
String

服務主要名稱 (SPN),用來唯一識別要驗證的伺服器。

傳回

工作物件,表示非同步作業。

例外狀況

targetNamenull

-或-

credentialnull

驗證失敗。 您可以使用這個物件重試驗證。

驗證失敗。 您可以使用這個物件重試驗證。

已經進行驗證。

-或-

這個資料流先前是用來以伺服器的身分嘗試驗證。 您不能使用資料流以用戶端身分重試驗證。

此物件已關閉。

備註

模擬層級為 Identification,安全性層級為 EncryptAndSign,而且會要求相互驗證。 類別 NegotiateStream 會建構用於相互驗證的SPN。

ChannelBinding用於在 參數中binding傳遞至這個方法的 擴充保護,會由應用程式從TransportContext相關聯 SslStream上的 屬性擷取。

驗證成功時,您必須檢查 IsEncryptedIsSigned 屬性,以判斷 所使用的 NegotiateStream安全性服務。 IsMutuallyAuthenticated檢查 屬性,以判斷是否發生相互驗證。

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 AuthenticateAsClient(NetworkCredential, ChannelBinding, String)例外狀況。

另請參閱

適用於

AuthenticateAsClientAsync(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

來源:
NegotiateStream.cs
來源:
NegotiateStream.cs
來源:
NegotiateStream.cs

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的認證和驗證選項。

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::Net::NetworkCredential ^ credential, System::String ^ targetName, System::Net::Security::ProtectionLevel requiredProtectionLevel, System::Security::Principal::TokenImpersonationLevel allowedImpersonationLevel);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.NetworkCredential credential, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel);
abstract member AuthenticateAsClientAsync : System.Net.NetworkCredential * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : System.Net.NetworkCredential * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (credential As NetworkCredential, targetName As String, requiredProtectionLevel As ProtectionLevel, allowedImpersonationLevel As TokenImpersonationLevel) As Task

參數

credential
NetworkCredential

建立用戶端識別所用的 NetworkCredential

targetName
String

服務主要名稱 (SPN),用來唯一識別要驗證的伺服器。

requiredProtectionLevel
ProtectionLevel

其中一個 ProtectionLevel 值,表示資料流的安全性服務。

allowedImpersonationLevel
TokenImpersonationLevel

其中一個 TokenImpersonationLevel 值,表示伺服器要如何使用用戶端的認證來存取資源。

傳回

工作物件,表示非同步作業。

例外狀況

allowedImpersonationLevel 不是有效的值。

targetName 為 null。

驗證失敗。 您可以使用這個物件重試驗證。

驗證失敗。 您可以使用這個物件重試驗證。

此物件已關閉。

已經進行驗證。

-或-

這個資料流先前是用來以伺服器的身分嘗試驗證。 您不能使用資料流以用戶端身分重試驗證。

備註

requiredProtectionLevel使用 參數來要求使用已驗證數據流傳輸之數據的安全性服務。 例如,若要讓數據加密並簽署,請 EncryptAndSign 指定 值。 成功的驗證不保證已授與所要求的 ProtectionLevel 。 您必須檢查 IsEncryptedIsSigned 屬性,以判斷 所使用的 NegotiateStream安全性服務。

如果驗證失敗,您會收到 AuthenticationExceptionInvalidCredentialException。 在此情況下,您可以使用不同的認證重試驗證。

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 AuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)例外狀況。

適用於

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

來源:
NegotiateStream.cs
來源:
NegotiateStream.cs
來源:
NegotiateStream.cs

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。 驗證處理序使用指定的認證、驗證選項和通道繫結。

public:
 virtual System::Threading::Tasks::Task ^ AuthenticateAsClientAsync(System::Net::NetworkCredential ^ credential, System::Security::Authentication::ExtendedProtection::ChannelBinding ^ binding, System::String ^ targetName, System::Net::Security::ProtectionLevel requiredProtectionLevel, System::Security::Principal::TokenImpersonationLevel allowedImpersonationLevel);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding? binding, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel);
public virtual System.Threading.Tasks.Task AuthenticateAsClientAsync (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding binding, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel);
abstract member AuthenticateAsClientAsync : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel -> System.Threading.Tasks.Task
override this.AuthenticateAsClientAsync : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel -> System.Threading.Tasks.Task
Public Overridable Function AuthenticateAsClientAsync (credential As NetworkCredential, binding As ChannelBinding, targetName As String, requiredProtectionLevel As ProtectionLevel, allowedImpersonationLevel As TokenImpersonationLevel) As Task

參數

credential
NetworkCredential

建立用戶端識別所用的 NetworkCredential

binding
ChannelBinding

用於延伸保護的 ChannelBinding

targetName
String

服務主要名稱 (SPN),用來唯一識別要驗證的伺服器。

requiredProtectionLevel
ProtectionLevel

其中一個 ProtectionLevel 值,表示資料流的安全性服務。

allowedImpersonationLevel
TokenImpersonationLevel

其中一個 TokenImpersonationLevel 值,表示伺服器要如何使用用戶端的認證來存取資源。

傳回

工作物件,表示非同步作業。

例外狀況

targetNamenull

-或-

credentialnull

allowedImpersonationLevel 不是有效的值。

驗證失敗。 您可以使用這個物件重試驗證。

驗證失敗。 您可以使用這個物件重試驗證。

已經進行驗證。

-或-

這個資料流先前是用來以伺服器的身分嘗試驗證。 您不能使用資料流以用戶端身分重試驗證。

此物件已關閉。

備註

requiredProtectionLevel使用 參數來要求使用已驗證數據流傳輸之數據的安全性服務。 例如,若要讓數據加密並簽署,請 EncryptAndSign 指定 值。 成功的驗證不保證已授與所要求的 ProtectionLevel 。 您必須檢查 IsEncryptedIsSigned 屬性,以判斷 所使用的 NegotiateStream安全性服務。

ChannelBinding用於在 參數中binding傳遞至這個方法的 擴充保護,會由應用程式從TransportContext相關聯 SslStream上的 屬性擷取。

如果驗證失敗,您會收到 AuthenticationExceptionInvalidCredentialException。 在此情況下,您可以使用不同的認證重試驗證。

這個方法會儲存在工作中,它會傳回方法同步對應專案可以擲回的所有非使用例外狀況。 如果例外狀況儲存在傳回的工作中,則會在等候工作時擲回該例外狀況。 使用例外狀況,例如 ArgumentException仍會同步擲回。 如需預存例外狀況,請參閱 擲回的 AuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)例外狀況。

另請參閱

適用於