Share via


NegotiateStream.BeginAuthenticateAsClient 方法

定义

开始一个异步操作,以对客户端-服务器连接中的客户端进行身份验证。

重载

BeginAuthenticateAsClient(AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 此方法不会进入阻止状态。

BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据。 此方法不会进入阻止状态。

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和通道绑定。 此方法不会进入阻止状态。

BeginAuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和身份验证选项。 此方法不会进入阻止状态。

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据、身份验证选项和通道绑定。 此方法不会进入阻止状态。

注解

身份验证正在进行时,此方法的重载不会阻止。 若要在等待身份验证完成时阻止,请使用 方法之 AuthenticateAsClient 一。

BeginAuthenticateAsClient(AsyncCallback, Object)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 此方法不会进入阻止状态。

public:
 virtual IAsyncResult ^ BeginAuthenticateAsClient(AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (AsyncCallback? asyncCallback, object? asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (AsyncCallback asyncCallback, object asyncState);
abstract member BeginAuthenticateAsClient : AsyncCallback * obj -> IAsyncResult
override this.BeginAuthenticateAsClient : AsyncCallback * obj -> IAsyncResult
Public Overridable Function BeginAuthenticateAsClient (asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult

参数

asyncCallback
AsyncCallback

一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。

asyncState
Object

一个用户定义对象,其中包含该操作的相关信息。 操作完成时,此对象传递给 asyncCallback 委托。

返回

一个指示异步操作状态的 IAsyncResult 对象。

例外

身份验证失败。 可以使用此对象尝试重新进行身份验证。

身份验证失败。 可以使用此对象尝试重新进行身份验证。

此对象已关闭。

已进行了身份验证。

- 或 -

此流先前被尝试作为服务器进行身份验证。 不能尝试将该流作为客户端重新进行身份验证。

示例

以下示例演示如何调用此方法以开始对客户端进行异步身份验证。

// Establish the remote endpoint for the socket.
// For this example, use the local machine.
IPHostEntry^ ipHostInfo = Dns::GetHostEntry( Dns::GetHostName() );
IPAddress^ ipAddress = ipHostInfo->AddressList[ 0 ];

// Client and server use port 11000. 
IPEndPoint^ remoteEP = gcnew IPEndPoint( ipAddress,11000 );

// Create a TCP/IP socket.
client = gcnew TcpClient;

// Connect the socket to the remote endpoint.
client->Connect( remoteEP );
Console::WriteLine( L"Client connected to {0}.", remoteEP );

// Ensure the client does not close when there is 
// still data to be sent to the server.
client->LingerState = (gcnew LingerOption( true,0 ));

// Request authentication.
NetworkStream^ clientStream = client->GetStream();
NegotiateStream^ authStream = gcnew NegotiateStream( clientStream,false );

// Pass the NegotiateStream as the AsyncState object 
// so that it is available to the callback delegate.
IAsyncResult^ ar = authStream->BeginAuthenticateAsClient( gcnew AsyncCallback( EndAuthenticateCallback ), authStream );

// Establish the remote endpoint for the socket.
// For this example, use the local machine.
IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
IPAddress ipAddress = ipHostInfo.AddressList[0];
// Client and server use port 11000.
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000);
// Create a TCP/IP socket.
client = new TcpClient();
// Connect the socket to the remote endpoint.
client.Connect(remoteEP);
Console.WriteLine("Client connected to {0}.", remoteEP.ToString());
// Ensure the client does not close when there is
// still data to be sent to the server.
client.LingerState = new LingerOption(true, 0);
// Request authentication.
NetworkStream clientStream = client.GetStream();
NegotiateStream authStream = new NegotiateStream(clientStream, false);
// Pass the NegotiateStream as the AsyncState object
// so that it is available to the callback delegate.
Task authenticateTask = authStream
    .AuthenticateAsClientAsync()
    .ContinueWith(task =>
    {
        Console.WriteLine("Client ending authentication...");
        Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel);
    });

' Establish the remote endpoint for the socket.
' For this example, use the local machine.
Dim ipHostInfo = Dns.GetHostEntry("localhost")
Dim ipAddress = ipHostInfo.AddressList(0)

' Client and server use port 11000. 
Dim remoteEP As New IPEndPoint(ipAddress, 11000)

' Create a TCP/IP socket.
client = New TcpClient()

' Connect the socket to the remote endpoint.
client.Connect(remoteEP)
Console.WriteLine("Client connected to {0}.", remoteEP.ToString())

' Ensure the client does not close when there is 
' still data to be sent to the server.
client.LingerState = (New LingerOption(True, 0))

' Request authentication.
Dim clientStream = client.GetStream()
Dim authStream As New NegotiateStream(clientStream, False)

' Pass the NegotiateStream as the AsyncState object 
' so that it is available to the callback delegate.
Dim ar = authStream.BeginAuthenticateAsClient(
    New AsyncCallback(AddressOf EndAuthenticateCallback), authStream)

注解

身份验证使用客户端的 DefaultCredentials。 未为服务器指定服务主体名称 (SPN) 。 模拟级别为 Identification,安全级别为 EncryptAndSign。 类 NegotiateStream 将构造用于相互身份验证的 SPN。

此方法是异步的,在操作完成时不会阻止。 若要在操作完成之前阻止,请使用 方法重载之 AuthenticateAsClient 一。

异步身份验证操作必须通过调用 EndAuthenticateAsClient 方法来完成。 通常,委托会调用 asyncCallback 方法。 有关使用异步编程模型的详细信息,请参阅 异步调用同步方法

如果身份验证失败,则会收到 AuthenticationExceptionInvalidCredentialException。 在这种情况下,可以使用其他凭据重试身份验证。

适用于

BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据。 此方法不会进入阻止状态。

public:
 virtual IAsyncResult ^ BeginAuthenticateAsClient(System::Net::NetworkCredential ^ credential, System::String ^ targetName, AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, string targetName, AsyncCallback? asyncCallback, object? asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, string targetName, AsyncCallback asyncCallback, object asyncState);
abstract member BeginAuthenticateAsClient : System.Net.NetworkCredential * string * AsyncCallback * obj -> IAsyncResult
override this.BeginAuthenticateAsClient : System.Net.NetworkCredential * string * AsyncCallback * obj -> IAsyncResult
Public Overridable Function BeginAuthenticateAsClient (credential As NetworkCredential, targetName As String, asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult

参数

credential
NetworkCredential

用于确立客户端身份的 NetworkCredential

targetName
String

唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。

asyncCallback
AsyncCallback

一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。

asyncState
Object

一个用户定义对象,其中包含写操作的相关信息。 操作完成时,此对象传递给 asyncCallback 委托。

返回

一个指示异步操作状态的 IAsyncResult 对象。

例外

credentialnull

targetNamenull

身份验证失败。 可以使用此对象尝试重新进行身份验证。

身份验证失败。 可以使用此对象尝试重新进行身份验证。

此对象已关闭。

已进行了身份验证。

- 或 -

此流先前被尝试作为服务器进行身份验证。 不能尝试将该流作为客户端重新进行身份验证。

注解

此方法是异步的,在操作完成时不会阻止。 若要在操作完成之前阻止,请使用 方法重载之 AuthenticateAsClient 一。

异步身份验证操作必须通过调用 EndAuthenticateAsClient 方法来完成。 通常,委托会调用 asyncCallback 方法。 有关使用异步编程模型的详细信息,请参阅 异步调用同步方法

如果身份验证失败,则会收到 AuthenticationExceptionInvalidCredentialException。 在这种情况下,可以使用其他凭据重试身份验证。

适用于

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, AsyncCallback, Object)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和通道绑定。 此方法不会进入阻止状态。

public:
 virtual IAsyncResult ^ BeginAuthenticateAsClient(System::Net::NetworkCredential ^ credential, System::Security::Authentication::ExtendedProtection::ChannelBinding ^ binding, System::String ^ targetName, AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding? binding, string targetName, AsyncCallback? asyncCallback, object? asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding binding, string targetName, AsyncCallback asyncCallback, object asyncState);
abstract member BeginAuthenticateAsClient : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string * AsyncCallback * obj -> IAsyncResult
override this.BeginAuthenticateAsClient : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string * AsyncCallback * obj -> IAsyncResult
Public Overridable Function BeginAuthenticateAsClient (credential As NetworkCredential, binding As ChannelBinding, targetName As String, asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult

参数

credential
NetworkCredential

用于确立客户端身份的 NetworkCredential

binding
ChannelBinding

用于扩展保护的 ChannelBinding

targetName
String

唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。

asyncCallback
AsyncCallback

一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。

asyncState
Object

一个用户定义对象,其中包含写操作的相关信息。 操作完成时,此对象传递给 asyncCallback 委托。

返回

一个指示异步操作状态的 IAsyncResult 对象。

例外

credentialnull

targetNamenull

身份验证失败。 可以使用此对象尝试重新进行身份验证。

身份验证失败。 可以使用此对象尝试重新进行身份验证。

已进行了身份验证。

- 或 -

此流先前被尝试作为服务器进行身份验证。 不能尝试将该流作为客户端重新进行身份验证。

此对象已关闭。

注解

此方法是异步的,在操作完成时不会阻止。 若要在操作完成之前阻止,请使用 方法重载之 AuthenticateAsClient 一。

异步身份验证操作必须通过调用 EndAuthenticateAsClient 方法来完成。 通常,委托会调用 asyncCallback 方法。 有关使用异步编程模型的详细信息,请参阅 异步调用同步方法

如果身份验证失败,则会收到 AuthenticationExceptionInvalidCredentialException。 在这种情况下,可以使用其他凭据重试身份验证。

另请参阅

适用于

BeginAuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据和身份验证选项。 此方法不会进入阻止状态。

public:
 virtual IAsyncResult ^ BeginAuthenticateAsClient(System::Net::NetworkCredential ^ credential, System::String ^ targetName, System::Net::Security::ProtectionLevel requiredProtectionLevel, System::Security::Principal::TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback asyncCallback, object asyncState);
abstract member BeginAuthenticateAsClient : System.Net.NetworkCredential * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel * AsyncCallback * obj -> IAsyncResult
override this.BeginAuthenticateAsClient : System.Net.NetworkCredential * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel * AsyncCallback * obj -> IAsyncResult
Public Overridable Function BeginAuthenticateAsClient (credential As NetworkCredential, targetName As String, requiredProtectionLevel As ProtectionLevel, allowedImpersonationLevel As TokenImpersonationLevel, asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult

参数

credential
NetworkCredential

用于确立客户端身份的 NetworkCredential

targetName
String

唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。

requiredProtectionLevel
ProtectionLevel

ProtectionLevel 值之一,指示流的安全服务。

allowedImpersonationLevel
TokenImpersonationLevel

TokenImpersonationLevel 值之一,指示服务器使用客户端凭据访问资源的方式。

asyncCallback
AsyncCallback

一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。

asyncState
Object

一个用户定义对象,其中包含写操作的相关信息。 操作完成时,此对象传递给 asyncCallback 委托。

返回

一个指示异步操作状态的 IAsyncResult 对象。

例外

credentialnull

targetNamenull

身份验证失败。 可以使用此对象尝试重新进行身份验证。

身份验证失败。 可以使用此对象尝试重新进行身份验证。

此对象已关闭。

已进行了身份验证。

- 或 -

此流先前被尝试作为服务器进行身份验证。 不能尝试将该流作为客户端重新进行身份验证。

注解

requiredProtectionLevel使用 参数为使用经过身份验证的流传输的数据请求安全服务。 例如,若要对数据进行加密和签名,请 EncryptAndSign 指定 值。 成功的身份验证不保证已授予请求 ProtectionLevel 的 。 必须检查 IsEncryptedIsSigned 属性来确定 所使用的NegotiateStream安全服务。

此方法是异步的,在操作完成时不会阻止。 若要在操作完成之前阻止,请使用 方法重载之 AuthenticateAsClient 一。

异步身份验证操作必须通过调用 EndAuthenticateAsClient 方法来完成。 通常,委托会调用 asyncCallback 方法。 有关使用异步编程模型的详细信息,请参阅 异步调用同步方法

如果身份验证失败,则会收到 AuthenticationExceptionInvalidCredentialException。 在这种情况下,可以使用其他凭据重试身份验证。

适用于

BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

Source:
NegotiateStream.cs
Source:
NegotiateStream.cs
Source:
NegotiateStream.cs

客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。 身份验证过程使用指定的凭据、身份验证选项和通道绑定。 此方法不会进入阻止状态。

public:
 virtual IAsyncResult ^ BeginAuthenticateAsClient(System::Net::NetworkCredential ^ credential, System::Security::Authentication::ExtendedProtection::ChannelBinding ^ binding, System::String ^ targetName, System::Net::Security::ProtectionLevel requiredProtectionLevel, System::Security::Principal::TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback ^ asyncCallback, System::Object ^ asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding? binding, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback? asyncCallback, object? asyncState);
public virtual IAsyncResult BeginAuthenticateAsClient (System.Net.NetworkCredential credential, System.Security.Authentication.ExtendedProtection.ChannelBinding binding, string targetName, System.Net.Security.ProtectionLevel requiredProtectionLevel, System.Security.Principal.TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback asyncCallback, object asyncState);
abstract member BeginAuthenticateAsClient : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel * AsyncCallback * obj -> IAsyncResult
override this.BeginAuthenticateAsClient : System.Net.NetworkCredential * System.Security.Authentication.ExtendedProtection.ChannelBinding * string * System.Net.Security.ProtectionLevel * System.Security.Principal.TokenImpersonationLevel * AsyncCallback * obj -> IAsyncResult
Public Overridable Function BeginAuthenticateAsClient (credential As NetworkCredential, binding As ChannelBinding, targetName As String, requiredProtectionLevel As ProtectionLevel, allowedImpersonationLevel As TokenImpersonationLevel, asyncCallback As AsyncCallback, asyncState As Object) As IAsyncResult

参数

credential
NetworkCredential

用于确立客户端身份的 NetworkCredential

binding
ChannelBinding

用于扩展保护的 ChannelBinding

targetName
String

唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。

requiredProtectionLevel
ProtectionLevel

ProtectionLevel 值之一,指示流的安全服务。

allowedImpersonationLevel
TokenImpersonationLevel

TokenImpersonationLevel 值之一,指示服务器使用客户端凭据访问资源的方式。

asyncCallback
AsyncCallback

一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。

asyncState
Object

一个用户定义对象,其中包含写操作的相关信息。 操作完成时,此对象传递给 asyncCallback 委托。

返回

一个指示异步操作状态的 IAsyncResult 对象。

例外

credentialnull

targetNamenull

身份验证失败。 可以使用此对象尝试重新进行身份验证。

身份验证失败。 可以使用此对象尝试重新进行身份验证。

已进行了身份验证。

- 或 -

此流先前被尝试作为服务器进行身份验证。 不能尝试将该流作为客户端重新进行身份验证。

此对象已关闭。

注解

requiredProtectionLevel使用 参数为使用经过身份验证的流传输的数据请求安全服务。 例如,若要对数据进行加密和签名,请 EncryptAndSign 指定 值。 成功的身份验证不保证已授予请求 ProtectionLevel 的 。 必须检查 IsEncryptedIsSigned 属性来确定 所使用的NegotiateStream安全服务。

此方法是异步的,在操作完成时不会阻止。 若要在操作完成之前阻止,请使用 方法重载之 AuthenticateAsClient 一。

异步身份验证操作必须通过调用 EndAuthenticateAsClient 方法来完成。 通常,委托会调用 asyncCallback 方法。 有关使用异步编程模型的详细信息,请参阅 异步调用同步方法

如果身份验证失败,则会收到 AuthenticationExceptionInvalidCredentialException。 在这种情况下,可以使用其他凭据重试身份验证。

另请参阅

适用于