This documentation is archived and is not being maintained.
ProtectionLevel Enumeration
Visual Studio 2010
Indicates the security services requested for an authenticated stream.
Assembly: System (in System.dll)
This enumeration is used by the NegotiateStream class.
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition Platform Note: Only None is supported.
The following code example demonstrates creating and using a client-side NegotiateStream.
#using <System.dll> using namespace System; using namespace System::Net; using namespace System::Net::Security; using namespace System::Net::Sockets; using namespace System::Security::Principal; static void DisplayStreamProperties( NegotiateStream^ stream ) { Console::WriteLine( L"Can read: {0}", stream->CanRead ); Console::WriteLine( L"Can write: {0}", stream->CanWrite ); Console::WriteLine( L"Can seek: {0}", stream->CanSeek ); try { // If the underlying stream supports it, display the length. Console::WriteLine( L"Length: {0}", stream->Length ); } catch ( NotSupportedException^ ) { Console::WriteLine( L"Cannot get the length of the underlying stream." ); } if ( stream->CanTimeout ) { Console::WriteLine( L"Read time-out: {0}", stream->ReadTimeout ); Console::WriteLine( L"Write time-out: {0}", stream->WriteTimeout ); } } static void DisplayAuthenticationProperties( NegotiateStream^ stream ) { Console::WriteLine( L"IsAuthenticated: {0}", stream->IsAuthenticated ); Console::WriteLine( L"IsMutuallyAuthenticated: {0}", stream->IsMutuallyAuthenticated ); Console::WriteLine( L"IsEncrypted: {0}", stream->IsEncrypted ); Console::WriteLine( L"IsSigned: {0}", stream->IsSigned ); Console::WriteLine( L"ImpersonationLevel: {0}", stream->ImpersonationLevel ); Console::WriteLine( L"IsServer: {0}", stream->IsServer ); } int main() { // 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. TcpClient^ 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 ); // Request authentication for the client only (no mutual authentication). // Authenicate using the client's default credetials. // Permit the server to impersonate the client to access resources on the server only. // Request that data be transmitted using encryption and data signing. authStream->AuthenticateAsClient( dynamic_cast<NetworkCredential^>(CredentialCache::DefaultCredentials), L"", ProtectionLevel::EncryptAndSign, TokenImpersonationLevel::Impersonation ); DisplayAuthenticationProperties( authStream ); DisplayStreamProperties( authStream ); if ( authStream->CanWrite ) { // Encode the test data into a byte array. array<Byte>^message = System::Text::Encoding::UTF8->GetBytes( L"Hello from the client." ); authStream->Write( message, 0, message->Length ); authStream->Flush(); Console::WriteLine( L"Sent {0} bytes.", message->Length ); } // Close the client connection. authStream->Close(); Console::WriteLine( L"Client closed." ); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: