NegotiateStream.RemoteIdentity 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得共用這個經過驗證資料流之遠端群體識別的相關資訊。
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伺服器。