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
繼承
繼承

範例

下列範例示範使用之用戶端-伺服器連接的用戶端 NegotiateStreamThe 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.
            Task authenticateTask = authStream
                .AuthenticateAsClientAsync()
                .ContinueWith(task =>
                {
                    Console.WriteLine("Client ending authentication...");
                    Console.WriteLine("ImpersonationLevel: {0}", authStream.ImpersonationLevel);
                });

            Console.WriteLine("Client waiting for authentication...");
            // Wait until the result is available.
            authenticateTask.Wait();
            // 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.");
            Task writeTask = authStream
                .WriteAsync(message, 0, message.Length)
                .ContinueWith(task =>
                {
                    Console.WriteLine("Client ending write operation...");
                });

            writeTask.Wait();
            Console.WriteLine("Sent {0} bytes.", message.Length);
            // Close the client connection.
            authStream.Close();
            Console.WriteLine("Client closed.");
        }
    }

    // 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;
                // 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);
                }
            }
        }

        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.
            Task authTask = authStream
                .AuthenticateAsServerAsync()
                .ContinueWith(task => { EndAuthenticateCallback(cState); });

            // Any exceptions that occurred during authentication are
            // thrown by the EndAuthenticateAsServer method.
            try
            {
                // This call blocks until the authentication is complete.
                authTask.Wait();
            }
            catch (AuthenticationException e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Authentication failed - closing connection.");
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Closing connection.");
                return;
            }

            Task<int> readTask = authStream
                .ReadAsync(cState.Buffer, 0, cState.Buffer.Length);

            readTask
                .ContinueWith((task) => { EndReadCallback(cState, task.Result); })
                .Wait();
            // Finished with the current client.
            authStream.Close();
            clientRequest.Close();
        }

        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
            );
        }

        private static void EndReadCallback(ClientState cState, int bytes)
        {
            NegotiateStream authStream = (NegotiateStream)cState.AuthenticatedStream;
            // Read the client message.
            try
            {
                cState.Message.Append(Encoding.UTF8.GetChars(cState.Buffer, 0, bytes));
                if (bytes != 0)
                {
                    Task<int> readTask = authStream.ReadAsync(cState.Buffer, 0, cState.Buffer.Length);
                    readTask
                        .ContinueWith(task => { EndReadCallback(cState, task.Result); })
                        .Wait();

                    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);
                return;
            }
            IIdentity id = authStream.RemoteIdentity;
            Console.WriteLine("{0} says {1}", id.Name, cState.Message.ToString());
        }
    }
    // ClientState is the AsyncState object.
    internal class ClientState
    {
        private StringBuilder _message = null;

        internal ClientState(AuthenticatedStream a, TcpClient theClient)
        {
            AuthenticatedStream = a;
            Client = theClient;
        }
        internal TcpClient Client { get; }

        internal AuthenticatedStream AuthenticatedStream { get; }

        internal byte[] Buffer { get; } = new byte[2048];

        internal StringBuilder Message
        {
            get { return _message ??= new StringBuilder(); }
        }
    }
}

備註

使用 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 或非同步方法要求驗證 BeginAuthenticateAsServerServers request authentication using the synchronous AuthenticateAsServer or asynchronous BeginAuthenticateAsServer methods. 用戶端和伺服器(選擇性)是使用 Negotiate 安全性通訊協定進行驗證。The client, and optionally the server, is authenticated using the Negotiate security protocol. 如果用戶端和伺服器都支援 Kerberos 通訊協定,則會使用 Kerberos 通訊協定進行驗證;否則會使用 NTLM。The Kerberos protocol is used for authentication if both client and server support it; otherwise NTLM is used. 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. 您可以使用屬性取得遠端用戶端或伺服器的相關資訊 RemoteIdentityYou 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 WriteAsyncYou send data using the synchronous Write or asynchronous BeginWrite or WriteAsync methods. 您可以使用同步 Read 或非同步或方法來接收資料 ReadAsync BeginReadYou receive data using the synchronous Read or asynchronous ReadAsync or BeginRead methods. 如果啟用了安全性服務(例如加密或簽章),則會自動將這些服務套用至您的資料 NegotiateStreamIf security services such as encryption or signing are enabled, these are automatically applied to your data by the NegotiateStream.

NegotiateStream會使用您在建立時提供的資料流程來傳輸資料 NegotiateStreamThe 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.

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

開始非同步的讀取作業。Begins an asynchronous read operation. (請考慮用 ReadAsync(Byte[], Int32, Int32) 替代。)(Consider using ReadAsync(Byte[], Int32, Int32) instead.)

(繼承來源 Stream)
BeginWrite(Byte[], Int32, Int32, AsyncCallback, Object)

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

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

開始非同步的寫入作業。Begins an asynchronous write operation. (請考慮用 WriteAsync(Byte[], Int32, Int32) 替代。)(Consider using WriteAsync(Byte[], Int32, Int32) instead.)

(繼承來源 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.

Dispose(Boolean)

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

(繼承來源 AuthenticatedStream)
DisposeAsync()

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

DisposeAsync()

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

(繼承來源 AuthenticatedStream)
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).

EndRead(IAsyncResult)

等候暫止的非同步讀取完成。Waits for the pending asynchronous read to complete. (請考慮用 ReadAsync(Byte[], Int32, Int32) 替代。)(Consider using ReadAsync(Byte[], Int32, Int32) instead.)

(繼承來源 Stream)
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).

EndWrite(IAsyncResult)

結束非同步的寫入作業。Ends an asynchronous write operation. (請考慮用 WriteAsync(Byte[], Int32, Int32) 替代。)(Consider using WriteAsync(Byte[], Int32, Int32) instead.)

(繼承來源 Stream)
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)

將任何緩衝資料以非同步方式寫入底層裝置。Asynchronously writes any buffered data to the underlying device.

FlushAsync(CancellationToken)

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

(繼承來源 Stream)
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)

以非同步方式,從此資料流讀取資料,並將其儲存在指定的陣列中。Reads data asynchronously from this stream and stores it in the specified array.

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)

以非同步方式,從 NegotiateStream 讀取資料,並以非同步方式將其儲存在位元組記憶體範圍內。Reads data asynchronously from the NegotiateStream and stores it in a byte memory range as an asynchronous operation.

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)

以非同步方式,將指定的 Byte 數目寫入底層資料流。Write asynchronously the specified number of Bytes to the underlying 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)

以非同步方式,將指定的 Byte 數目寫入底層資料流。Write asynchronously the specified number of Bytes to the underlying 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)

擴充方法

ConfigureAwait(IAsyncDisposable, Boolean)

設定如何執行從非同步可處置項目傳回的工作 await。Configures how awaits on the tasks returned from an async disposable are performed.

適用於