NegotiateStream 類別

定義

提供資料流,該資料流會在用戶端與伺服器之間的通訊中,使用交涉安全性通訊協定驗證用戶端,並選擇性地驗證伺服器。Provides a stream that uses the Negotiate security protocol to authenticate the client, and optionally the server, in client-server communication.

public ref class NegotiateStream : System::Net::Security::AuthenticatedStream
public class NegotiateStream : System.Net.Security.AuthenticatedStream
type NegotiateStream = class
    inherit AuthenticatedStream
Public Class NegotiateStream
Inherits AuthenticatedStream
繼承

範例

下列範例示範使用 NegotiateStream之用戶端伺服器連接的用戶端。The following example demonstrates the client side of a client-server connection that uses the NegotiateStream. 用戶端會以非同步方式進行驗證,並將訊息傳送至伺服器。The client authenticates and sends a message to the server asynchronously.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Security;
using namespace System::Net::Sockets;
using namespace System::Text;

// The following class displays the properties of an authenticatedStream.
public ref class AuthenticatedStreamReporter
{
public:
   static void DisplayProperties( AuthenticatedStream^ 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"IsServer: {0}", stream->IsServer );
   }

};


public ref class ASynchronousAuthenticatingTcpClient
{
private:
   static TcpClient^ client = nullptr;

public:
   void 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.
      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 );
      
      Console::WriteLine( L"Client waiting for authentication..." );
      
      // Wait until the result is available.
      ar->AsyncWaitHandle->WaitOne();
      
      // Display the properties of the authenticated stream.
      AuthenticatedStreamReporter::DisplayProperties( authStream );
      
      // Send a message to the server.
      // Encode the test data into a byte array.
      array<Byte>^message = Encoding::UTF8->GetBytes( L"Hello from the client." );
      ar = authStream->BeginWrite( message, 0, message->Length, gcnew AsyncCallback( EndWriteCallback ), authStream );
      
      ar->AsyncWaitHandle->WaitOne();
      Console::WriteLine( L"Sent {0} bytes.", message->Length );
      
      // Close the client connection.
      authStream->Close();
      Console::WriteLine( L"Client closed." );
   }


   // The following method is called when the authentication completes.
   static void EndAuthenticateCallback( IAsyncResult^ ar )
   {
      Console::WriteLine( L"Client ending authentication..." );
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(ar->AsyncState);
      
      // End the asynchronous operation.
      authStream->EndAuthenticateAsClient( ar );
      
      //         Console.WriteLine("AllowedImpersonation: {0}", authStream.AllowedImpersonation);
   }


   // The following method is called when the write operation completes.
   static void EndWriteCallback( IAsyncResult^ ar )
   {
      Console::WriteLine( L"Client ending write operation..." );
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(ar->AsyncState);
      
      // End the asynchronous operation.
      authStream->EndWrite( ar );
   }

};

void main()
{
   ASynchronousAuthenticatingTcpClient^ aatc = gcnew ASynchronousAuthenticatingTcpClient;
   aatc->Main();
}
using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Text;

namespace Examples.NegotiateStreamExample
{
    public class ASynchronousAuthenticatingTcpClient 
    {   
        static TcpClient client = null;

        public static void Main(String[] args)  
        {
            // 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.
            IAsyncResult ar = authStream.BeginAuthenticateAsClient(
                new AsyncCallback(EndAuthenticateCallback),
                authStream
                );
            Console.WriteLine("Client waiting for authentication...");
            // Wait until the result is available.
            ar.AsyncWaitHandle.WaitOne();
            // Display the properties of the authenticated stream.
            AuthenticatedStreamReporter.DisplayProperties(authStream);
            // Send a message to the server.
            // Encode the test data into a byte array.
            byte[] message = Encoding.UTF8.GetBytes("Hello from the client.");
            ar = authStream.BeginWrite(message, 0, message.Length,
                new AsyncCallback(EndWriteCallback),
                authStream);
            ar.AsyncWaitHandle.WaitOne();
            Console.WriteLine("Sent {0} bytes.", message.Length);
            // Close the client connection.
            authStream.Close();
            Console.WriteLine("Client closed.");
        }
        // The following method is called when the authentication completes.
        public static void EndAuthenticateCallback (IAsyncResult ar)
        {
            Console.WriteLine("Client ending authentication...");
            NegotiateStream authStream = (NegotiateStream) ar.AsyncState;
            Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel);

            // End the asynchronous operation.
            authStream.EndAuthenticateAsClient(ar);
        }
        // The following method is called when the write operation completes.
        public static void EndWriteCallback (IAsyncResult ar)
        {
            Console.WriteLine("Client ending write operation...");
            NegotiateStream authStream = (NegotiateStream) ar.AsyncState;

            // End the asynchronous operation.
            authStream.EndWrite(ar);
        }
    }

    // The following class displays the properties of an authenticatedStream.
    public class AuthenticatedStreamReporter
{
    public static void DisplayProperties(AuthenticatedStream stream)
   {
        Console.WriteLine("IsAuthenticated: {0}", stream.IsAuthenticated);
        Console.WriteLine("IsMutuallyAuthenticated: {0}", stream.IsMutuallyAuthenticated);
        Console.WriteLine("IsEncrypted: {0}", stream.IsEncrypted);
        Console.WriteLine("IsSigned: {0}", stream.IsSigned);
        Console.WriteLine("IsServer: {0}", stream.IsServer);
    }
}
}
Imports System.Text
Imports System.Net.Sockets
Imports System.Net.Security
Imports System.Net

Namespace Examples.NegotiateStreamExample

    Public Class ASynchronousAuthenticatingTcpClient

        Shared client As TcpClient = Nothing

        Public Shared Sub Main(args As String())
            ' 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)

            Console.WriteLine("Client waiting for authentication...")

            ' Wait until the result is available.
            ar.AsyncWaitHandle.WaitOne()

            ' Display the properties of the authenticated stream.
            AuthenticatedStreamReporter.DisplayProperties(authStream)

            ' Send a message to the server.
            ' Encode the test data into a byte array.
            Dim message = Encoding.UTF8.GetBytes("Hello from the client.")
            ar = authStream.BeginWrite(message, 0, message.Length, 
                New AsyncCallback(AddressOf EndWriteCallback), authStream)
            ar.AsyncWaitHandle.WaitOne()
            Console.WriteLine("Sent {0} bytes.", message.Length)

            ' Close the client connection.
            authStream.Close()
            Console.WriteLine("Client closed.")

        End Sub

        ' The following method is called when the authentication completes.
        Public Shared Sub EndAuthenticateCallback(ar As IAsyncResult)

            Console.WriteLine("Client ending authentication...")
            Dim authStream = CType(ar.AsyncState, NegotiateStream)
            Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel)

            ' End the asynchronous operation.
            authStream.EndAuthenticateAsClient(ar)

        End Sub

        ' The following method is called when the write operation completes.
        Public Shared Sub EndWriteCallback(ar As IAsyncResult)

            Console.WriteLine("Client ending write operation...")
            Dim authStream = CType(ar.AsyncState, NegotiateStream)

            ' End the asynchronous operation.
            authStream.EndWrite(ar)

        End Sub
    End Class

    ' The following class displays the properties of an AuthenticatedStream.
    Public Class AuthenticatedStreamReporter
        Public Shared Sub DisplayProperties(stream As AuthenticatedStream)
            Console.WriteLine("IsAuthenticated: {0}", stream.IsAuthenticated)
            Console.WriteLine("IsMutuallyAuthenticated: {0}", stream.IsMutuallyAuthenticated)
            Console.WriteLine("IsEncrypted: {0}", stream.IsEncrypted)
            Console.WriteLine("IsSigned: {0}", stream.IsSigned)
            Console.WriteLine("IsServer: {0}", stream.IsServer)
        End Sub
    End Class
End Namespace

下列程式碼範例示範用戶端伺服器連線的伺服器端,該連接會使用 NegotiateStream 來驗證用戶端,並讀取用戶端所傳送的訊息。The following code example demonstrates the server side of a client-server connection that uses the NegotiateStream to authenticate the client and read a message sent by the client.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Security;
using namespace System::Net::Sockets;
using namespace System::Security::Authentication;
using namespace System::Security::Principal;
using namespace System::Text;
using namespace System::IO;
using namespace System::Threading;

// ClientState is the AsyncState object.
private ref class ClientState
{
private:
   AuthenticatedStream^ authStream;
   TcpClient^ client;
   array<Byte>^buffer;
   StringBuilder^ message;
   ManualResetEvent^ waiter;

internal:
   ClientState( AuthenticatedStream^ a, TcpClient^ theClient )
   {
      authStream = a;
      client = theClient;
      message = nullptr;
      buffer = gcnew array<Byte>(2048);
      waiter = gcnew ManualResetEvent( false );
   }

internal:
   property TcpClient^ Client 
   {
      TcpClient^ get()
      {
         return client;
      }
   }

   property AuthenticatedStream^ AuthStream 
   {
      AuthenticatedStream^ get()
      {
         return authStream;
      }
  }

   property array<Byte>^ Buffer 
   {
      array<Byte>^ get()
      {
         return buffer;
      }

   }

   property StringBuilder^ Message 
   {
      StringBuilder^ get()
      {
         if ( message == nullptr )
                  message = gcnew StringBuilder;

         return message;
      }

   }

   property ManualResetEvent^ Waiter 
   {
      ManualResetEvent^ get()
      {
         return waiter;
      }

   }

};

public ref class AsynchronousAuthenticatingTcpListener
{
public:
   int Main()
   {
      
      // Create an IPv4 TCP/IP socket. 
      TcpListener^ listener = gcnew TcpListener( IPAddress::Any,11000 );
      
      // Listen for incoming connections.
      listener->Start();
      while ( true )
      {
         TcpClient^ clientRequest = nullptr;
         
         // Application blocks while waiting for an incoming connection.
         // Type CNTL-C to terminate the server.
         clientRequest = listener->AcceptTcpClient();
         Console::WriteLine( L"Client connected." );
         
         // A client has connected. 
         try
         {
            AuthenticateClient( clientRequest );
         }
         catch ( Exception^ e ) 
         {
            Console::WriteLine( e );
            continue;
         }

      }
   }


   static void AuthenticateClient( TcpClient^ clientRequest )
   {
      NetworkStream^ stream = clientRequest->GetStream();
      
      // Create the NegotiateStream.
      NegotiateStream^ authStream = gcnew NegotiateStream( stream,false );
      
      // Save the current client and NegotiateStream instance 
      // in a ClientState object.
      ClientState^ cState = gcnew ClientState( authStream,clientRequest );
      
      // Listen for the client authentication request.
      authStream->BeginAuthenticateAsServer( gcnew AsyncCallback( EndAuthenticateCallback ), cState );
      
      // Wait until the authentication completes.
      cState->Waiter->WaitOne();
      cState->Waiter->Reset();
      authStream->BeginRead( cState->Buffer, 0, cState->Buffer->Length, gcnew AsyncCallback( EndReadCallback ), cState );
      cState->Waiter->WaitOne();
      
      // Finished with the current client.
      authStream->Close();
      clientRequest->Close();
   }


   // The following method is invoked by the
   // BeginServerAuthenticate callback delegate.
   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();
   }


   static void EndReadCallback( IAsyncResult^ ar )
   {
      
      // Get the saved data.
      ClientState^ cState = dynamic_cast<ClientState^>(ar->AsyncState);
      TcpClient^ clientRequest = cState->Client;
      NegotiateStream^ authStream = dynamic_cast<NegotiateStream^>(cState->AuthStream);
      
      // Get the buffer that stores the message sent by the client.
      int bytes = -1;
      
      // Read the client message.
      try
      {
         bytes = authStream->EndRead( ar );
         cState->Message->Append( Encoding::UTF8->GetChars( cState->Buffer, 0, bytes ) );
         if ( bytes != 0 )
         {
            authStream->BeginRead( cState->Buffer, 0, cState->Buffer->Length, gcnew AsyncCallback( EndReadCallback ), cState );
            return;
         }
      }
      catch ( Exception^ e ) 
      {
         
         // A real application should do something
         // useful here, such as logging the failure.
         Console::WriteLine( L"Client message exception:" );
         Console::WriteLine( e );
         cState->Waiter->Set();
         return;
      }

      IIdentity^ id = authStream->RemoteIdentity;
      Console::WriteLine( L"{0} says {1}", id->Name, cState->Message );
      cState->Waiter->Set();
   }

};

void main()
{
   AsynchronousAuthenticatingTcpListener^ aatl = gcnew AsynchronousAuthenticatingTcpListener;
   aatl->Main();
}

using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Principal;
using System.Text;
using System.IO;
using System.Threading;

namespace Examples.NegotiateStreamExample
{
    public class AsynchronousAuthenticatingTcpListener 
    {
        public static void Main() 
        {   
            // Create an IPv4 TCP/IP socket. 
            TcpListener listener = new TcpListener(IPAddress.Any, 11000);
            // Listen for incoming connections.
            listener.Start();
            while (true) 
            {
                TcpClient clientRequest = null;
                // Application blocks while waiting for an incoming connection.
                // Type CNTL-C to terminate the server.
                clientRequest = listener.AcceptTcpClient();
                Console.WriteLine("Client connected.");
                // A client has connected. 
                try
                {
                    AuthenticateClient (clientRequest);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    continue;
                }

            }
        
        }
        public static void AuthenticateClient(TcpClient clientRequest)
        {
            NetworkStream stream = clientRequest.GetStream(); 
            // Create the NegotiateStream.
            NegotiateStream authStream = new NegotiateStream(stream, false); 
            // Save the current client and NegotiateStream instance 
            // in a ClientState object.
            ClientState cState = new ClientState(authStream, clientRequest);
            // Listen for the client authentication request.
            authStream.BeginAuthenticateAsServer (
                new AsyncCallback(EndAuthenticateCallback),
                cState
                );
            // Wait until the authentication completes.
            cState.Waiter.WaitOne();
            cState.Waiter.Reset();
            authStream.BeginRead(cState.Buffer, 0, cState.Buffer.Length, 
                   new AsyncCallback(EndReadCallback), 
                   cState);
            cState.Waiter.WaitOne();
            // Finished with the current client.
            authStream.Close();
            clientRequest.Close();
        }
        // The following method is invoked by the
        // BeginAuthenticateAsServer callback delegate.

        public static void EndAuthenticateCallback (IAsyncResult ar)
        {
            // Get the saved data.
            ClientState cState = (ClientState) ar.AsyncState;
            TcpClient clientRequest = cState.Client;
            NegotiateStream authStream = (NegotiateStream) cState.AuthenticatedStream;
            Console.WriteLine("Ending authentication.");
            // Any exceptions that occurred during authentication are
            // thrown by the EndAuthenticateAsServer method.
            try 
            {
                // This call blocks until the authentication is complete.
                authStream.EndAuthenticateAsServer(ar);
            }
            catch (AuthenticationException e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Authentication failed - closing connection.");
                cState.Waiter.Set();
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Closing connection.");
                cState.Waiter.Set();
                return;
            }
            // Display properties of the authenticated client.
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} was authenticated using {1}.", 
                id.Name, 
                id.AuthenticationType
                );
            cState.Waiter.Set();

    }
        public static void EndReadCallback(IAsyncResult ar)
        {
            // Get the saved data.
            ClientState cState = (ClientState) ar.AsyncState;
            TcpClient clientRequest = cState.Client;
            NegotiateStream authStream = (NegotiateStream) cState.AuthenticatedStream; 
            // Get the buffer that stores the message sent by the client.
            int bytes = -1;
            // Read the client message.
            try
            {
                    bytes = authStream.EndRead(ar);
                    cState.Message.Append(Encoding.UTF8.GetChars(cState.Buffer, 0, bytes));
                    if (bytes != 0)
                    {
                         authStream.BeginRead(cState.Buffer, 0, cState.Buffer.Length, 
                               new AsyncCallback(EndReadCallback), 
                               cState);
                               return;
                 }
            }
            catch (Exception e)
            {
                // A real application should do something
                // useful here, such as logging the failure.
                Console.WriteLine("Client message exception:");
                Console.WriteLine(e);
                cState.Waiter.Set();
                return;
            }
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} says {1}", id.Name, cState.Message.ToString());
            cState.Waiter.Set();
        }
    }
    // ClientState is the AsyncState object.
    internal class ClientState
    {
        private AuthenticatedStream authStream = null;
        private  TcpClient client = null;
        byte[] buffer = new byte[2048];
        StringBuilder message = null;
        ManualResetEvent waiter = new ManualResetEvent(false);
        internal ClientState(AuthenticatedStream a, TcpClient theClient)
        {
            authStream = a;
            client = theClient;
        }
        internal TcpClient Client
        { 
            get { return client;}
        }
        internal AuthenticatedStream AuthenticatedStream
        {
            get { return authStream;}
        }
        internal byte[] Buffer
        {
              get { return buffer;}
        }
        internal StringBuilder Message
        {
            get 
            { 
                if (message == null)
                    message = new StringBuilder();
                return message;
             }
        }
        internal ManualResetEvent Waiter
        {
            get 
            { 
                return waiter;
             }
        }
    }
}

備註

使用 NegotiateStream 類別進行驗證,並協助保護用戶端與伺服器之間傳輸的資訊。Use the NegotiateStream class for authentication and to help secure information transmitted between a client and a server. 使用 NegotiateStream,您可以執行下列動作。Using NegotiateStream, you can do the following.

  • 將用戶端的認證傳送到伺服器,以進行模擬或委派。Send the client's credentials to the server for Impersonation or Delegation.

  • 要求伺服器驗證。Request server authentication.

  • 加密和/或簽署資料後再進行傳輸。Encrypt and/or sign data before transmitting it.

必須先執行驗證,才能傳輸資訊。Authentication must be performed before transmitting information. 用戶端會使用同步 AuthenticateAsClient 方法(會封鎖直到驗證完成)或非同步 BeginAuthenticateAsClient 方法(在等候驗證完成時不會封鎖)來要求驗證。Clients request authentication using the synchronous AuthenticateAsClient methods, which block until the authentication completes, or the asynchronous BeginAuthenticateAsClient methods, which do not block while waiting for the authentication to complete. 伺服器會使用同步 AuthenticateAsServer 或非同步 BeginAuthenticateAsServer 方法來要求驗證。Servers request authentication using the synchronous AuthenticateAsServer or asynchronous BeginAuthenticateAsServer methods. 用戶端和伺服器(選擇性)會使用 Negotiate 安全性通訊協定進行驗證。The client, and optionally the server, is authenticated using the Negotiate security protocol. 在 Windows 95/98 系統上,Windows NT LAN Manager (NTLM)是用於驗證的通訊協定。On Windows 95/98 systems, Windows NT LAN Manager (NTLM) is the protocol used for authentication. 在其他平臺上,如果用戶端和伺服器都支援,則會使用 Kerberos 通訊協定來進行驗證;否則會使用 NTLM。On other platforms the Kerberos protocol is used for authentication if both client and server support it; otherwise NTLM is used. 如需這些通訊協定的詳細說明,請參閱 MSDN 上的 Platform SDK 檔,網址為 msdn.microsoft.com/library/。For detailed descriptions of these protocols, see the Platform SDK documentation on MSDN, at msdn.microsoft.com/library/. NegotiateStream 類別會使用安全性支援提供者介面(SSPI)來執行驗證。The NegotiateStream class performs the authentication using the Security Support Provider Interface (SSPI).

當驗證成功時,您必須檢查 IsEncryptedIsSigned 屬性,以判斷 NegotiateStream 會使用哪些安全性服務,協助保護您的資料在傳輸期間的安全。When authentication succeeds, you must check the IsEncrypted and IsSigned properties to determine what security services will be used by the NegotiateStream to help secure your data during transmission. 請檢查 IsMutuallyAuthenticated 屬性,以判斷是否發生相互驗證。Check the IsMutuallyAuthenticated property to determine whether mutual authentication occurred. 您可以使用 RemoteIdentity 屬性來取得遠端用戶端或伺服器的相關資訊。You can get information about the remote client or server using the RemoteIdentity property.

如果驗證失敗,您會收到 AuthenticationExceptionInvalidCredentialExceptionIf the authentication fails, you will receive an AuthenticationException or a InvalidCredentialException. 在此情況下,您可以使用不同的認證重試驗證。In this case, you can retry the authentication with a different credential.

您可以使用同步 Write 或非同步 BeginWrite 方法來傳送資料。You send data using the synchronous Write or asynchronous BeginWrite methods. 您會使用同步 Read 或非同步 BeginRead 方法來接收資料。You receive data using the synchronous Read or asynchronous BeginRead methods. 如果已啟用安全性服務(例如加密或簽署),則 NegotiateStream會將這些服務自動套用至您的資料。If security services such as encryption or signing are enabled, these are automatically applied to your data by the NegotiateStream.

NegotiateStream 會使用您在建立 NegotiateStream時提供的資料流程來傳輸資料。The NegotiateStream transmits data using a stream that you supply when creating the NegotiateStream. 當您提供此基礎資料流程時,您可以選擇是否要關閉 NegotiateStream 也會關閉基礎資料流程。When you supply this underlying stream, you have the option to specify whether closing the NegotiateStream also closes the underlying stream.

建構函式

NegotiateStream(Stream)

使用指定的 NegotiateStream,初始化 Stream 類別的新執行個體。Initializes a new instance of the NegotiateStream class using the specified Stream.

NegotiateStream(Stream, Boolean)

使用指定的 NegotiateStream 和資料流結束行為,初始化 Stream 類別的新執行個體。Initializes a new instance of the NegotiateStream class using the specified Stream and stream closure behavior.

屬性

CanRead

取得 Boolean 值,指示基礎資料流是否可讀取。Gets a Boolean value that indicates whether the underlying stream is readable.

CanSeek

取得 Boolean 值,指示基礎資料流是否可搜尋。Gets a Boolean value that indicates whether the underlying stream is seekable.

CanTimeout

取得 Boolean 值,指示基礎資料流是否支援逾時。Gets a Boolean value that indicates whether the underlying stream supports time-outs.

CanWrite

取得 Boolean 值,指示基礎資料流是否可寫入。Gets a Boolean value that indicates whether the underlying stream is writable.

ImpersonationLevel

取得值,指示伺服器如何使用用戶端的認證。Gets a value that indicates how the server can use the client's credentials.

InnerStream

取得這個 AuthenticatedStream 用來傳送和接收資料的資料流。Gets the stream used by this AuthenticatedStream for sending and receiving data.

(繼承來源 AuthenticatedStream)
IsAuthenticated

取得 Boolean 值,指示驗證是否成功。Gets a Boolean value that indicates whether authentication was successful.

IsEncrypted

取得 Boolean 值,指示這個 NegotiateStream 是否使用資料加密。Gets a Boolean value that indicates whether this NegotiateStream uses data encryption.

IsMutuallyAuthenticated

取得 Boolean 值,指示伺服器和用戶端是否都已經過驗證。Gets a Boolean value that indicates whether both the server and the client have been authenticated.

IsServer

取得 Boolean 值,指示這個 NegotiateStream 使用之連接的本機端是否以伺服器的身分驗證。Gets a Boolean value that indicates whether the local side of the connection used by this NegotiateStream was authenticated as the server.

IsSigned

取得 Boolean 值,指示使用此資料流傳送的資料是否簽章。Gets a Boolean value that indicates whether the data sent using this stream is signed.

LeaveInnerStreamOpen

取得這個 AuthenticatedStream 用來傳送和接收資料的資料流是否保持開啟狀態。Gets whether the stream used by this AuthenticatedStream for sending and receiving data has been left open.

(繼承來源 AuthenticatedStream)
Length

取得基礎資料流的長度。Gets the length of the underlying stream.

Position

取得或設定基礎資料流中目前的位置。Gets or sets the current position in the underlying stream.

ReadTimeout

取得或設定讀取作業封鎖等待資料的時間長度。Gets or sets the amount of time a read operation blocks waiting for data.

RemoteIdentity

取得共用這個經過驗證資料流之遠端群體識別的相關資訊。Gets information about the identity of the remote party sharing this authenticated stream.

WriteTimeout

取得或設定寫入作業封鎖等待資料的時間長度。Gets or sets the amount of time a write operation blocks waiting for data.

方法

AuthenticateAsClient()

由用戶端呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection.

AuthenticateAsClient(NetworkCredential, ChannelBinding, String)

由用戶端呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的用戶端認證和通道繫結。The authentication process uses the specified client credential and the channel binding.

AuthenticateAsClient(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

由用戶端呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的認證、驗證選項和通道繫結。The authentication process uses the specified credential, authentication options, and channel binding.

AuthenticateAsClient(NetworkCredential, String)

由用戶端呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的用戶端認證。The authentication process uses the specified client credential.

AuthenticateAsClient(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

由用戶端呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的認證和驗證選項。The authentication process uses the specified credentials and authentication options.

AuthenticateAsClientAsync()

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation.

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的用戶端認證和通道繫結。The authentication process uses the specified client credential and the channel binding.

AuthenticateAsClientAsync(NetworkCredential, ChannelBinding, String, ProtectionLevel, TokenImpersonationLevel)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的認證、驗證選項和通道繫結。The authentication process uses the specified credential, authentication options, and channel binding.

AuthenticateAsClientAsync(NetworkCredential, String)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的用戶端認證。The authentication process uses the specified client credential.

AuthenticateAsClientAsync(NetworkCredential, String, ProtectionLevel, TokenImpersonationLevel)

由用戶端呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by clients to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的認證和驗證選項。The authentication process uses the specified credentials and authentication options.

AuthenticateAsServer()

由伺服器呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection.

AuthenticateAsServer(ExtendedProtectionPolicy)

由伺服器呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的延伸保護原則。The authentication process uses the specified extended protection policy.

AuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

由伺服器呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的伺服器認證、驗證選項和延伸保護原則。The authentication process uses the specified server credentials, authentication options, and extended protection policy.

AuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

由伺服器呼叫以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的伺服器認證和驗證選項。The authentication process uses the specified server credentials and authentication options.

AuthenticateAsServerAsync()

由伺服器呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation.

AuthenticateAsServerAsync(ExtendedProtectionPolicy)

由伺服器呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的延伸保護原則。The authentication process uses the specified extended protection policy.

AuthenticateAsServerAsync(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel)

由伺服器呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的伺服器認證、驗證選項和延伸保護原則。The authentication process uses the specified server credentials, authentication options, and extended protection policy.

AuthenticateAsServerAsync(NetworkCredential, ProtectionLevel, TokenImpersonationLevel)

由伺服器呼叫做為非同步作業,以驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to authenticate the client, and optionally the server, in a client-server connection as an asynchronous operation. 驗證處理序使用指定的伺服器認證和驗證選項。The authentication process uses the specified server credentials and authentication options.

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, 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, 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.

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, 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.

BeginAuthenticateAsServer(AsyncCallback, Object)

由伺服器呼叫以開始非同步作業,以便驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 這個方法不會封鎖。This method does not block.

BeginAuthenticateAsServer(ExtendedProtectionPolicy, AsyncCallback, Object)

由伺服器呼叫以開始非同步作業,以便驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的延伸保護原則。The authentication process uses the specified extended protection policy. 這個方法不會封鎖。This method does not block.

BeginAuthenticateAsServer(NetworkCredential, ExtendedProtectionPolicy, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

由伺服器呼叫以開始非同步作業,以便驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的伺服器認證、驗證選項和延伸保護原則。The authentication process uses the specified server credentials, authentication options, and extended protection policy. 這個方法不會封鎖。This method does not block.

BeginAuthenticateAsServer(NetworkCredential, ProtectionLevel, TokenImpersonationLevel, AsyncCallback, Object)

由伺服器呼叫以開始非同步作業,以便驗證用戶端與伺服器連接中的用戶端,並選擇性地驗證伺服器。Called by servers to begin an asynchronous operation to authenticate the client, and optionally the server, in a client-server connection. 驗證處理序使用指定的伺服器認證和驗證選項。The authentication process uses the specified server credentials and authentication options. 這個方法不會封鎖。This method does not block.

BeginRead(Byte[], Int32, Int32, AsyncCallback, Object)

開始非同步讀取作業,這個作業會從資料流中讀取資料並將其儲存於指定的陣列中。Begins an asynchronous read operation that reads data from the stream and stores it in the specified array.

BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

開始非同步寫入作業,此作業會從指定的緩衝區寫入 Byte 至資料流。Begins an asynchronous write operation that writes Bytes from the specified buffer to the stream.

Close()

關閉目前資料流和釋放與目前資料流相關聯的任何資源 (例如通訊端和檔案控制代碼)。Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. 請確定正確地處置資料流,而非呼叫這個方法。Instead of calling this method, ensure that the stream is properly disposed.

(繼承來源 Stream)
CopyTo(Stream)

從目前資料流讀取位元組,並將其寫入另一個資料流中。Reads the bytes from the current stream and writes them to another stream.

(繼承來源 Stream)
CopyTo(Stream, Int32)

使用指定的緩衝區大小,從目前資料流讀取所有位元組,並將其寫入另一個資料流中。Reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(繼承來源 Stream)
CopyToAsync(Stream)

以非同步的方式從目前資料流讀取所有位元組,並將其寫入另一個資料流中。Asynchronously reads the bytes from the current stream and writes them to another stream.

(繼承來源 Stream)
CopyToAsync(Stream, CancellationToken)

使用指定的取消權杖,以非同步的方式從目前資料流讀取位元組,並將其寫入另一個資料流。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified cancellation token.

(繼承來源 Stream)
CopyToAsync(Stream, Int32)

使用指定的緩衝區大小,以非同步的方式從目前資料流讀取所有位元組,並將其寫入另一個資料流中。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

(繼承來源 Stream)
CopyToAsync(Stream, Int32, CancellationToken)

使用指定的緩衝區大小和取消語彙基元,以非同步的方式從目前資料流讀取位元組,並將其寫入另一個資料流。Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.

(繼承來源 Stream)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
CreateWaitHandle()

配置 WaitHandle 物件。Allocates a WaitHandle object.

(繼承來源 Stream)
Dispose()

釋出 Stream 所使用的全部資源。Releases all resources used by the Stream.

(繼承來源 Stream)
Dispose(Boolean)

釋放 NegotiateStream 所使用的 unmanaged 資源並選擇性地釋放 managed 的資源。Releases the unmanaged resources used by the NegotiateStream and optionally releases the managed resources.

DisposeAsync()

以非同步方式釋放 NegotiateStream 使用的非受控與受控資源。Asynchronously releases the unmanaged and managed resources used by the NegotiateStream.

EndAuthenticateAsClient(IAsyncResult)

結束藉由呼叫 BeginAuthenticateAsClient 啟動的暫止非同步用戶端驗證作業。Ends a pending asynchronous client authentication operation that was started with a call to BeginAuthenticateAsClient.

EndAuthenticateAsServer(IAsyncResult)

結束藉由呼叫 BeginAuthenticateAsServer 啟動的暫止非同步用戶端驗證作業。Ends a pending asynchronous client authentication operation that was started with a call to BeginAuthenticateAsServer.

EndRead(IAsyncResult)

結束藉由呼叫 BeginRead(Byte[], Int32, Int32, AsyncCallback, Object) 啟動的非同步讀取作業。Ends an asynchronous read operation that was started with a call to BeginRead(Byte[], Int32, Int32, AsyncCallback, Object).

EndWrite(IAsyncResult)

結束藉由呼叫 BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object) 啟動的非同步寫入作業。Ends an asynchronous write operation that was started with a call to BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object).

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Flush()

造成任何緩衝資料都將寫入基礎裝置。Causes any buffered data to be written to the underlying device.

FlushAsync()

以非同步的方式清除這個資料流的所有緩衝區,並造成所有緩衝資料都寫入基礎裝置。Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device.

(繼承來源 Stream)
FlushAsync(CancellationToken)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ObjectInvariant()

提供 Contract 的支援。Provides support for a Contract.

(繼承來源 Stream)
Read(Byte[], Int32, Int32)

從這個資料流中讀取資料並將其儲存於指定的陣列中。Reads data from this stream and stores it in the specified array.

Read(Span<Byte>)

當在衍生類別中覆寫時,自目前資料流讀取一連串的位元組,並依所讀取的位元組數目進階資料流中的位置。When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(繼承來源 Stream)
ReadAsync(Byte[], Int32, Int32)

以非同步的方式從目前的資料流讀取位元組序列,並依讀取的位元組數將資料流中的位置往前移。Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

(繼承來源 Stream)
ReadAsync(Byte[], Int32, Int32, CancellationToken)

以非同步的方式從目前資料流讀取一連串的位元組、依所讀取的位元組數目進階資料流中的位置,以及監視取消要求。Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(繼承來源 Stream)
ReadAsync(Memory<Byte>, CancellationToken)

以非同步的方式從目前資料流讀取一連串的位元組、依所讀取的位元組數目進階資料流中的位置,以及監視取消要求。Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

(繼承來源 Stream)
ReadByte()

從資料流讀取一個位元組,並將資料流的位置推進一個位元組;如果在資料流末端,則傳回 -1。Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

(繼承來源 Stream)
Seek(Int64, SeekOrigin)

擲回 NotSupportedExceptionThrows NotSupportedException.

SetLength(Int64)

設定基礎資料流的長度。Sets the length of the underlying stream.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
Write(Byte[], Int32, Int32)

使用指定的緩衝區和位移,將指定數目的 Byte 寫入至基礎資料流。Write the specified number of Bytes to the underlying stream using the specified buffer and offset.

Write(ReadOnlySpan<Byte>)

在衍生類別中覆寫時,將一連串的位元組寫入目前的資料流,並且由這個資料流中目前的位置前移寫入的位元組數目。When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(繼承來源 Stream)
WriteAsync(Byte[], Int32, Int32)

以非同步的方式將位元組序列寫入至目前的資料流,並依寫入的位元組數將資料流中目前的位置往前移。Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

(繼承來源 Stream)
WriteAsync(Byte[], Int32, Int32, CancellationToken)

以非同步的方式將一連串的位元組寫入目前的資料流,由這個資料流中目前的位置前移寫入的位元組數目,並且監視取消要求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(繼承來源 Stream)
WriteAsync(ReadOnlyMemory<Byte>, CancellationToken)

以非同步的方式將一連串的位元組寫入目前的資料流,由這個資料流中目前的位置前移寫入的位元組數目,並且監視取消要求。Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

(繼承來源 Stream)
WriteByte(Byte)

寫入一個位元組至資料流的目前位置,並將資料流位置推進一個位元組。Writes a byte to the current position in the stream and advances the position within the stream by one byte.

(繼承來源 Stream)

明確介面實作

IDisposable.Dispose()

釋出 Stream 所使用的全部資源。Releases all resources used by the Stream.

(繼承來源 Stream)

適用於

另請參閱