NegotiateStream.RemoteIdentity 属性

定义

获取有关共享此已验证身份的流的远程方的身份信息。

public:
 virtual property System::Security::Principal::IIdentity ^ RemoteIdentity { System::Security::Principal::IIdentity ^ get(); };
public virtual System.Security.Principal.IIdentity RemoteIdentity { get; }
member this.RemoteIdentity : System.Security.Principal.IIdentity
Public Overridable ReadOnly Property RemoteIdentity As IIdentity

属性值

IIdentity 对象,介绍远程端点的标识。

例外

身份验证失败或没有进行身份验证。

示例

下面的代码示例演示如何显示此属性的值。

static void EndAuthenticateCallback( IAsyncResult^ ar )
{
   
   // Get the saved data.
   ClientState^ cState = dynamic_cast<ClientState^>(ar->AsyncState);
   TcpClient^ clientRequest = cState->Client;
   NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(cState->AuthStream);
   Console::WriteLine( L"Ending authentication." );
   
   // Any exceptions that occurred during authentication are
   // thrown by the EndServerAuthenticate method.
   try
   {
      
      // This call blocks until the authentication is complete.
      authStream->EndAuthenticateAsServer( ar );
   }
   catch ( AuthenticationException^ e ) 
   {
      Console::WriteLine( e );
      Console::WriteLine( L"Authentication failed - closing connection." );
      cState->Waiter->Set();
      return;
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e );
      Console::WriteLine( L"Closing connection." );
      cState->Waiter->Set();
      return;
   }

   
   // Display properties of the authenticated client.
   IIdentity^ id = authStream->RemoteIdentity;
   Console::WriteLine( L"{0} was authenticated using {1}.", id->Name, id->AuthenticationType );
   cState->Waiter->Set();
}


private static void EndAuthenticateCallback(ClientState cState)
{
    // Get the saved data.
    NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
    Console.WriteLine("Ending authentication.");

    // Display properties of the authenticated client.
    IIdentity id = authStream.RemoteIdentity;
    Console.WriteLine("{0} was authenticated using {1}.",
        id.Name,
        id.AuthenticationType
    );
}

注解

当客户端访问时,此属性返回一个 GenericIdentity ,其中包含服务主体名称 (SPN) 的服务器和使用的身份验证协议。 当服务器访问时,此属性返回描述 WindowsIdentity 客户端的 。 WindowsIdentity如果 不可用,客户端信息将返回到 中的GenericIdentity服务器。

适用于