NegotiateStream.BeginAuthenticateAsClient 方法
定义
开始一个异步操作,以对客户端-服务器连接中的客户端进行身份验证。Begins an asynchronous operation to authenticate the client side of a client-server connection.
重载
| BeginAuthenticateAsClient(AsyncCallback, Object) |
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 此方法不会进入阻止状态。This method does not block. |
| BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object) |
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据。The authentication process uses the specified credentials. 此方法不会进入阻止状态。This method does not block. |
| BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, AsyncCallback, Object) |
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据和通道绑定。The authentication process uses the specified credentials and channel binding. 此方法不会进入阻止状态。This method does not block. |
| BeginAuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object) |
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据和身份验证选项。The authentication process uses the specified credentials and authentication options. 此方法不会进入阻止状态。This method does not block. |
| BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object) |
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据、身份验证选项和通道绑定。The authentication process uses the specified credentials, authentication options, and channel binding. 此方法不会进入阻止状态。This method does not block. |
注解
进行身份验证时,不会阻止此方法的重载。The overloads of this method do not block while authentication is in progress. 若要在等待身份验证完成时阻止,请使用其中一种 AuthenticateAsClient 方法。To block while waiting for the authentication to complete, use one of the AuthenticateAsClient methods.
BeginAuthenticateAsClient(AsyncCallback, Object)
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 此方法不会进入阻止状态。This method does not block.
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 委托,该委托引用当身份验证完成时要调用的方法。An AsyncCallback delegate that references the method to invoke when the authentication is complete.
- asyncState
- Object
一个用户定义对象,其中包含该操作的相关信息。A user-defined object containing information about the operation. 操作完成时,此对象传递给 asyncCallback 委托。This object is passed to the asyncCallback delegate when the operation completes.
返回
一个指示异步操作状态的 IAsyncResult 对象。An IAsyncResult object indicating the status of the asynchronous operation.
例外
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
此对象已关闭。This object has been closed.
已进行了身份验证。Authentication has already occurred.
- 或 --or-
此流先前被尝试作为服务器进行身份验证。This stream was used previously to attempt authentication as the server. 不能尝试将该流作为客户端重新进行身份验证。You cannot use the stream to retry authentication as the client.
示例
下面的示例演示如何调用此方法,以便为客户端开始异步身份验证。The following example demonstrates calling this method to begin an asynchronous authentication for the client.
// 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 。The authentication uses the client's DefaultCredentials. 未为服务器指定任何服务主体名称 (SPN) 。No Service Principal Name (SPN) is specified for the server. 模拟级别为 Identification ,安全级别为 EncryptAndSign 。The impersonation level is Identification, and the security level is EncryptAndSign. NegotiateStream类将构造用于相互身份验证的 SPN。The NegotiateStream class will construct the SPN used for mutual authentication.
此方法是异步的,并且在操作完成时不会被阻止。This method is asynchronous and does not block while the operation completes. 若要在操作完成之前一直阻止,请使用 AuthenticateAsClient 方法重载之一。To block until the operation completes, use one of the AuthenticateAsClient method overloads.
必须通过调用方法完成异步身份验证操作 EndAuthenticateAsClient 。The asynchronous authentication operation must be completed by calling the EndAuthenticateAsClient method. 通常,方法由 asyncCallback 委托调用。Typically, the method is invoked by the asyncCallback delegate. 有关使用异步编程模型的详细信息,请参阅 以异步方式调用同步方法For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously
如果身份验证失败,你将收到 AuthenticationException 或 InvalidCredentialException 。If the authentication fails, you receive an AuthenticationException or an InvalidCredentialException. 在这种情况下,你可以使用不同的凭据重试身份验证。In this case, you can retry the authentication with a different credential.
适用于
BeginAuthenticateAsClient(NetworkCredential, String, AsyncCallback, Object)
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据。The authentication process uses the specified credentials. 此方法不会进入阻止状态。This method does not block.
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。The NetworkCredential that is used to establish the identity of the client.
- targetName
- String
唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。The Service Principal Name (SPN) that uniquely identifies the server to authenticate.
- asyncCallback
- AsyncCallback
一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。An AsyncCallback delegate that references the method to invoke when the authentication is complete.
- asyncState
- Object
一个用户定义对象,其中包含写操作的相关信息。A user-defined object containing information about the write operation. 操作完成时,此对象传递给 asyncCallback 委托。This object is passed to the asyncCallback delegate when the operation completes.
返回
一个指示异步操作状态的 IAsyncResult 对象。An IAsyncResult object indicating the status of the asynchronous operation.
例外
credential 为 null。credential is null.
或-or-
targetName 为 null。targetName is null.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
此对象已关闭。This object has been closed.
已进行了身份验证。Authentication has already occurred.
- 或 --or-
此流先前被尝试作为服务器进行身份验证。This stream was used previously to attempt authentication as the server. 不能尝试将该流作为客户端重新进行身份验证。You cannot use the stream to retry authentication as the client.
注解
此方法是异步的,并且在操作完成时不会被阻止。This method is asynchronous and does not block while the operation completes. 若要在操作完成之前一直阻止,请使用 AuthenticateAsClient 方法重载之一。To block until the operation completes, use one of the AuthenticateAsClient method overloads.
必须通过调用方法完成异步身份验证操作 EndAuthenticateAsClient 。The asynchronous authentication operation must be completed by calling the EndAuthenticateAsClient method. 通常,方法由 asyncCallback 委托调用。Typically, the method is invoked by the asyncCallback delegate. 有关使用异步编程模型的详细信息,请参阅 以异步方式调用同步方法For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously
如果身份验证失败,你将收到 AuthenticationException 或 InvalidCredentialException 。If the authentication fails, you receive an AuthenticationException or an InvalidCredentialException. 在这种情况下,你可以使用不同的凭据重试身份验证。In this case, you can retry the authentication with a different credential.
适用于
BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, AsyncCallback, Object)
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据和通道绑定。The authentication process uses the specified credentials and channel binding. 此方法不会进入阻止状态。This method does not block.
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。The NetworkCredential that is used to establish the identity of the client.
- binding
- ChannelBinding
用于扩展保护的 ChannelBinding。The ChannelBinding that is used for extended protection.
- targetName
- String
唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。The Service Principal Name (SPN) that uniquely identifies the server to authenticate.
- asyncCallback
- AsyncCallback
一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。An AsyncCallback delegate that references the method to invoke when the authentication is complete.
- asyncState
- Object
一个用户定义对象,其中包含写操作的相关信息。A user-defined object containing information about the write operation. 操作完成时,此对象传递给 asyncCallback 委托。This object is passed to the asyncCallback delegate when the operation completes.
返回
一个指示异步操作状态的 IAsyncResult 对象。An IAsyncResult object indicating the status of the asynchronous operation.
例外
credential 为 null。credential is null.
或-or-
targetName 为 null。targetName is null.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
已进行了身份验证。Authentication has already occurred.
- 或 --or-
此流先前被尝试作为服务器进行身份验证。This stream was used previously to attempt authentication as the server. 不能尝试将该流作为客户端重新进行身份验证。You cannot use the stream to retry authentication as the client.
此对象已关闭。This object has been closed.
注解
此方法是异步的,并且在操作完成时不会被阻止。This method is asynchronous and does not block while the operation completes. 若要在操作完成之前一直阻止,请使用 AuthenticateAsClient 方法重载之一。To block until the operation completes, use one of the AuthenticateAsClient method overloads.
必须通过调用方法完成异步身份验证操作 EndAuthenticateAsClient 。The asynchronous authentication operation must be completed by calling the EndAuthenticateAsClient method. 通常,方法由 asyncCallback 委托调用。Typically, the method is invoked by the asyncCallback delegate. 有关使用异步编程模型的详细信息,请参阅 以异步方式调用同步方法For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously
如果身份验证失败,你将收到 AuthenticationException 或 InvalidCredentialException 。If the authentication fails, you receive an AuthenticationException or an InvalidCredentialException. 在这种情况下,你可以使用不同的凭据重试身份验证。In this case, you can retry the authentication with a different credential.
另请参阅
适用于
BeginAuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据和身份验证选项。The authentication process uses the specified credentials and authentication options. 此方法不会进入阻止状态。This method does not block.
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。The NetworkCredential that is used to establish the identity of the client.
- targetName
- String
唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。The Service Principal Name (SPN) that uniquely identifies the server to authenticate.
- requiredProtectionLevel
- ProtectionLevel
ProtectionLevel 值之一,指示流的安全服务。One of the ProtectionLevel values, indicating the security services for the stream.
- allowedImpersonationLevel
- TokenImpersonationLevel
TokenImpersonationLevel 值之一,指示服务器使用客户端凭据访问资源的方式。One of the TokenImpersonationLevel values, indicating how the server can use the client's credentials to access resources.
- asyncCallback
- AsyncCallback
一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。An AsyncCallback delegate that references the method to invoke when the authentication is complete.
- asyncState
- Object
一个用户定义对象,其中包含写操作的相关信息。A user-defined object containing information about the write operation. 操作完成时,此对象传递给 asyncCallback 委托。This object is passed to the asyncCallback delegate when the operation completes.
返回
一个指示异步操作状态的 IAsyncResult 对象。An IAsyncResult object indicating the status of the asynchronous operation.
例外
credential 为 null。credential is null.
或-or-
targetName 为 null。targetName is null.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
此对象已关闭。This object has been closed.
已进行了身份验证。Authentication has already occurred.
- 或 --or-
此流先前被尝试作为服务器进行身份验证。This stream was used previously to attempt authentication as the server. 不能尝试将该流作为客户端重新进行身份验证。You cannot use the stream to retry authentication as the client.
注解
使用 requiredProtectionLevel 参数为使用经过身份验证的流传输的数据请求安全服务。Use the requiredProtectionLevel parameter to request security services for data transmitted using the authenticated stream. 例如,若要对数据进行加密和签名,请指定 EncryptAndSign 值。For example, to have the data encrypted and signed, specify the EncryptAndSign value. 身份验证成功并不保证 ProtectionLevel 已授予请求。Successful authentication does not guarantee that the requested ProtectionLevel has been granted. 必须检查 IsEncrypted 和属性, IsSigned 以确定所使用的安全服务 NegotiateStream 。You must check the IsEncrypted and IsSigned properties to determine what security services are used by the NegotiateStream.
此方法是异步的,并且在操作完成时不会被阻止。This method is asynchronous and does not block while the operation completes. 若要在操作完成之前一直阻止,请使用 AuthenticateAsClient 方法重载之一。To block until the operation completes, use one of the AuthenticateAsClient method overloads.
必须通过调用方法完成异步身份验证操作 EndAuthenticateAsClient 。The asynchronous authentication operation must be completed by calling the EndAuthenticateAsClient method. 通常,方法由 asyncCallback 委托调用。Typically, the method is invoked by the asyncCallback delegate. 有关使用异步编程模型的详细信息,请参阅 以异步方式调用同步方法For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously
如果身份验证失败,你将收到 AuthenticationException 或 InvalidCredentialException 。If the authentication fails, you receive an AuthenticationException or an InvalidCredentialException. 在这种情况下,你可以使用不同的凭据重试身份验证。In this case, you can retry the authentication with a different credential.
适用于
BeginAuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)
客户端调用此方法开始一个异步操作,以对客户端/服务器连接中的客户端及服务器(可选)进行身份验证。Called by clients to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 身份验证过程使用指定的凭据、身份验证选项和通道绑定。The authentication process uses the specified credentials, authentication options, and channel binding. 此方法不会进入阻止状态。This method does not block.
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。The NetworkCredential that is used to establish the identity of the client.
- binding
- ChannelBinding
用于扩展保护的 ChannelBinding。The ChannelBinding that is used for extended protection.
- targetName
- String
唯一标识要进行身份验证的服务器的服务主体名称 (SPN)。The Service Principal Name (SPN) that uniquely identifies the server to authenticate.
- requiredProtectionLevel
- ProtectionLevel
ProtectionLevel 值之一,指示流的安全服务。One of the ProtectionLevel values, indicating the security services for the stream.
- allowedImpersonationLevel
- TokenImpersonationLevel
TokenImpersonationLevel 值之一,指示服务器使用客户端凭据访问资源的方式。One of the TokenImpersonationLevel values, indicating how the server can use the client's credentials to access resources.
- asyncCallback
- AsyncCallback
一个 AsyncCallback 委托,该委托引用当身份验证完成时要调用的方法。An AsyncCallback delegate that references the method to invoke when the authentication is complete.
- asyncState
- Object
一个用户定义对象,其中包含写操作的相关信息。A user-defined object containing information about the write operation. 操作完成时,此对象传递给 asyncCallback 委托。This object is passed to the asyncCallback delegate when the operation completes.
返回
一个指示异步操作状态的 IAsyncResult 对象。An IAsyncResult object indicating the status of the asynchronous operation.
例外
credential 为 null。credential is null.
或-or-
targetName 为 null。targetName is null.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
身份验证失败。The authentication failed. 可以使用此对象尝试重新进行身份验证。You can use this object to retry the authentication.
已进行了身份验证。Authentication has already occurred.
- 或 --or-
此流先前被尝试作为服务器进行身份验证。This stream was used previously to attempt authentication as the server. 不能尝试将该流作为客户端重新进行身份验证。You cannot use the stream to retry authentication as the client.
此对象已关闭。This object has been closed.
注解
使用 requiredProtectionLevel 参数为使用经过身份验证的流传输的数据请求安全服务。Use the requiredProtectionLevel parameter to request security services for data transmitted using the authenticated stream. 例如,若要对数据进行加密和签名,请指定 EncryptAndSign 值。For example, to have the data encrypted and signed, specify the EncryptAndSign value. 身份验证成功并不保证 ProtectionLevel 已授予请求。Successful authentication does not guarantee that the requested ProtectionLevel has been granted. 必须检查 IsEncrypted 和属性, IsSigned 以确定所使用的安全服务 NegotiateStream 。You must check the IsEncrypted and IsSigned properties to determine what security services are used by the NegotiateStream.
此方法是异步的,并且在操作完成时不会被阻止。This method is asynchronous and does not block while the operation completes. 若要在操作完成之前一直阻止,请使用 AuthenticateAsClient 方法重载之一。To block until the operation completes, use one of the AuthenticateAsClient method overloads.
必须通过调用方法完成异步身份验证操作 EndAuthenticateAsClient 。The asynchronous authentication operation must be completed by calling the EndAuthenticateAsClient method. 通常,方法由 asyncCallback 委托调用。Typically, the method is invoked by the asyncCallback delegate. 有关使用异步编程模型的详细信息,请参阅 以异步方式调用同步方法For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously
如果身份验证失败,你将收到 AuthenticationException 或 InvalidCredentialException 。If the authentication fails, you receive an AuthenticationException or an InvalidCredentialException. 在这种情况下,你可以使用不同的凭据重试身份验证。In this case, you can retry the authentication with a different credential.