工作者对象HttpWorkerRequest

在ASP.NET中,用于处理的请求,需要封装为HttpWorkerRequest类型的对象。该类为抽象类,定义在命名空间System.Web下。

#region Assembly System.Web.dll, v4.0.0.0
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.dll
#endregion

using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Web.Management;

namespace System.Web
{
    // Summary:
    //     This abstract class defines the base worker methods and enumerations used
    //     by ASP.NET managed code to process requests.
    [ComVisible(false)]
    public abstract class HttpWorkerRequest
    {
        // Summary:
        //     Specifies the index number for the Accept HTTP header.
        public const int HeaderAccept = 20;
        //
        // Summary:
        //     Specifies the index number for the Accept-Charset HTTP header.
        public const int HeaderAcceptCharset = 21;
        //
        // Summary:
        //     Specifies the index number for the Accept-Encoding HTTP header.
        public const int HeaderAcceptEncoding = 22;
        //
        // Summary:
        //     Specifies the index number for the Accept-Language HTTP header.
        public const int HeaderAcceptLanguage = 23;
        //
        // Summary:
        //     Specifies the index number for the Accept-Ranges HTTP header.
        public const int HeaderAcceptRanges = 20;
        //
        // Summary:
        //     Specifies the index number for the Age HTTP header.
        public const int HeaderAge = 21;
        //
        // Summary:
        //     Specifies the index number for the Allow HTTP header.
        public const int HeaderAllow = 10;
        //
        // Summary:
        //     Specifies the index number for the Authorization HTTP header.
        public const int HeaderAuthorization = 24;
        //
        // Summary:
        //     The index that represents the HTTP Cache-Control HTTP header.
        public const int HeaderCacheControl = 0;
        //
        // Summary:
        //     Specifies the index number for the Connection HTTP header.
        public const int HeaderConnection = 1;
        //
        // Summary:
        //     Specifies the index number for the Content-Encoding HTTP header.
        public const int HeaderContentEncoding = 13;
        //
        // Summary:
        //     Specifies the index number for the Content-Language HTTP header.
        public const int HeaderContentLanguage = 14;
        //
        // Summary:
        //     Specifies the index number for the Content-Length HTTP header.
        public const int HeaderContentLength = 11;
        //
        // Summary:
        //     Specifies the index number for the Content-Location HTTP header.
        public const int HeaderContentLocation = 15;
        //
        // Summary:
        //     Specifies the index number for the Content-MD5 HTTP header.
        public const int HeaderContentMd5 = 16;
        //
        // Summary:
        //     Specifies the index number for the Content-Range HTTP header.
        public const int HeaderContentRange = 17;
        //
        // Summary:
        //     Specifies the index number for the Content-Type HTTP header.
        public const int HeaderContentType = 12;
        //
        // Summary:
        //     Specifies the index number for the Cookie HTTP header.
        public const int HeaderCookie = 25;
        //
        // Summary:
        //     Specifies the index number for the Date HTTP header.
        public const int HeaderDate = 2;
        //
        // Summary:
        //     Specifies the index number for the ETag HTTP header.
        public const int HeaderEtag = 22;
        //
        // Summary:
        //     Specifies the index number for the Except HTTP header.
        public const int HeaderExpect = 26;
        //
        // Summary:
        //     Specifies the index number for the Expires HTTP header.
        public const int HeaderExpires = 18;
        //
        // Summary:
        //     Specifies the index number for the From HTTP header.
        public const int HeaderFrom = 27;
        //
        // Summary:
        //     Specifies the index number for the Host HTTP header.
        public const int HeaderHost = 28;
        //
        // Summary:
        //     Specifies the index number for the If-Match HTTP header.
        public const int HeaderIfMatch = 29;
        //
        // Summary:
        //     Specifies the index number for the If-Modified-Since HTTP header.
        public const int HeaderIfModifiedSince = 30;
        //
        // Summary:
        //     Specifies the index number for the If-None-Match HTTP header.
        public const int HeaderIfNoneMatch = 31;
        //
        // Summary:
        //     Specifies the index number for the If-Range HTTP header.
        public const int HeaderIfRange = 32;
        //
        // Summary:
        //     Specifies the index number for the If-Unmodified-Since HTTP header.
        public const int HeaderIfUnmodifiedSince = 33;
        //
        // Summary:
        //     Specifies the index number for the Keep-Alive HTTP header.
        public const int HeaderKeepAlive = 3;
        //
        // Summary:
        //     Specifies the index number for the Last-Modified HTTP header.
        public const int HeaderLastModified = 19;
        //
        // Summary:
        //     Specifies the index number for the Location HTTP header.
        public const int HeaderLocation = 23;
        //
        // Summary:
        //     Specifies the index number for the Max-Forwards HTTP header.
        public const int HeaderMaxForwards = 34;
        //
        // Summary:
        //     Specifies the index number for the Pragma HTTP header.
        public const int HeaderPragma = 4;
        //
        // Summary:
        //     Specifies the index number for the Proxy-Authenticate HTTP header.
        public const int HeaderProxyAuthenticate = 24;
        //
        // Summary:
        //     Specifies the index number for the Proxy-Authorization HTTP header.
        public const int HeaderProxyAuthorization = 35;
        //
        // Summary:
        //     Specifies the index number for the Range HTTP header.
        public const int HeaderRange = 37;
        //
        // Summary:
        //     Specifies the index number for the Referer HTTP header.
        public const int HeaderReferer = 36;
        //
        // Summary:
        //     Specifies the index number for the Retry-After HTTP header.
        public const int HeaderRetryAfter = 25;
        //
        // Summary:
        //     Specifies the index number for the Server HTTP header.
        public const int HeaderServer = 26;
        //
        // Summary:
        //     Specifies the index number for the Set-Cookie HTTP header.
        public const int HeaderSetCookie = 27;
        //
        // Summary:
        //     Specifies the index number for the TE HTTP header.
        public const int HeaderTe = 38;
        //
        // Summary:
        //     Specifies the index number for the Trailer HTTP header.
        public const int HeaderTrailer = 5;
        //
        // Summary:
        //     Specifies the index number for the Transfer-Encoding HTTP header.
        public const int HeaderTransferEncoding = 6;
        //
        // Summary:
        //     Specifies the index number for the Upgrade HTTP header.
        public const int HeaderUpgrade = 7;
        //
        // Summary:
        //     Specifies the index number for the User-Agent HTTP header.
        public const int HeaderUserAgent = 39;
        //
        // Summary:
        //     Specifies the index number for the Vary HTTP header.
        public const int HeaderVary = 28;
        //
        // Summary:
        //     Specifies the index number for the Via HTTP header.
        public const int HeaderVia = 8;
        //
        // Summary:
        //     Specifies the index number for the Warning HTTP header.
        public const int HeaderWarning = 9;
        //
        // Summary:
        //     Specifies the index number for the WWW-Authenticate HTTP header.
        public const int HeaderWwwAuthenticate = 29;
        //
        // Summary:
        //     Specifies a reason for the request.
        public const int ReasonCachePolicy = 2;
        //
        // Summary:
        //     Specifies a reason for the request.
        public const int ReasonCacheSecurity = 3;
        //
        // Summary:
        //     Specifies a reason for the request.
        public const int ReasonClientDisconnect = 4;
        //
        // Summary:
        //     Specifies a reason for the request. The default value is System.Web.HttpWorkerRequest.ReasonResponseCacheMiss.
        public const int ReasonDefault = 0;
        //
        // Summary:
        //     Specifies a reason for the request.
        public const int ReasonFileHandleCacheMiss = 1;
        //
        // Summary:
        //     Specifies a reason for the request.
        public const int ReasonResponseCacheMiss = 0;
        //
        // Summary:
        //     Specifies the index number for the Maximum HTTP request header.
        public const int RequestHeaderMaximum = 40;
        //
        // Summary:
        //     Specifies the index number for the Maximum HTTP response header.
        public const int ResponseHeaderMaximum = 30;

        // Summary:
        //     Initializes a new instance of the System.Web.HttpWorkerRequest class.
        protected HttpWorkerRequest();

        // Summary:
        //     Gets the full physical path to the Machine.config file.
        //
        // Returns:
        //     The physical path to the Machine.config file.
        public virtual string MachineConfigPath { get; }
        //
        // Summary:
        //     Gets the physical path to the directory where the ASP.NET binaries are installed.
        //
        // Returns:
        //     The physical directory to the ASP.NET binary files.
        public virtual string MachineInstallDirectory { get; }
        //
        // Summary:
        //     Gets the corresponding Event Tracking for Windows trace ID for the current
        //     request.
        //
        // Returns:
        //     A trace ID for the current ASP.NET request.
        public virtual Guid RequestTraceIdentifier { get; }
        //
        // Summary:
        //     Gets the full physical path to the root Web.config file.
        //
        // Returns:
        //     The physical path to the root Web.config file.
        public virtual string RootWebConfigPath { get; }
        //
        // Summary:
        //     Gets a value that indicates whether asynchronous flush operations are supported.
        //
        // Returns:
        //     true if asynchronous flush operations are supported; otherwise, false.
        public virtual bool SupportsAsyncFlush { get; }
        //
        // Summary:
        //     Gets a value that indicates whether asynchronous read operations are supported.
        //
        // Returns:
        //     true if asynchronous read operations are supported; otherwise, false.
        public virtual bool SupportsAsyncRead { get; }

        // Summary:
        //     Sends the currently buffered response to the client.
        //
        // Parameters:
        //   callback:
        //     The method to call when a corresponding asynchronous operation completes.
        //
        //   state:
        //     A user-provided object that distinguishes this particular asynchronous flush
        //     operation from other requests.
        //
        // Returns:
        //     The worker request buffers the status, headers, and response body until an
        //     asynchronous flush operation is initiated. If the underlying System.Web.HttpWorkerRequest
        //     object supports asynchronous flush and this method is called from an asynchronous
        //     module event or asynchronous handler, the send operation is performed asynchronously.
        //     Otherwise, the implementation performs a synchronous flush operation.
        public virtual IAsyncResult BeginFlush(AsyncCallback callback, object state);
        //
        // Summary:
        //     Begins an asynchronous read operation of the request entity body.
        //
        // Parameters:
        //   buffer:
        //     The buffer to read the data into.
        //
        //   offset:
        //     The byte offset in the buffer at which to begin writing data.
        //
        //   count:
        //     The maximum number of bytes to read.
        //
        //   callback:
        //     The method to call when a corresponding asynchronous operation completes.
        //
        //   state:
        //     A user-provided object that distinguishes this particular asynchronous read
        //     from other requests.
        public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state);
        //
        // Summary:
        //     Terminates the connection with the client.
        public virtual void CloseConnection();
        //
        // Summary:
        //     Waits for the pending asynchronous flush operation to complete.
        //
        // Parameters:
        //   asyncResult:
        //     A reference to the pending asynchronous request.
        public virtual void EndFlush(IAsyncResult asyncResult);
        //
        // Summary:
        //     Used by the runtime to notify the System.Web.HttpWorkerRequest that request
        //     processing for the current request is complete.
        public abstract void EndOfRequest();
        //
        // Summary:
        //     Waits for the pending asynchronous read operation to complete.
        //
        // Parameters:
        //   asyncResult:
        //     A reference to the pending asynchronous request.
        //
        // Returns:
        //     The number of bytes that have been read from the stream.
        public virtual int EndRead(IAsyncResult asyncResult);
        //
        // Summary:
        //     Sends all pending response data to the client.
        //
        // Parameters:
        //   finalFlush:
        //     true if this is the last time response data will be flushed; otherwise, false.
        public abstract void FlushResponse(bool finalFlush);
        //
        // Summary:
        //     Returns the virtual path to the currently executing server application.
        //
        // Returns:
        //     The virtual path of the current application.
        public virtual string GetAppPath();
        //
        // Summary:
        //     Returns the physical path to the currently executing server application.
        //
        // Returns:
        //     The physical path of the current application.
        public virtual string GetAppPathTranslated();
        //
        // Summary:
        //     When overridden in a derived class, returns the application pool ID for the
        //     current URL.
        //
        // Returns:
        //     Always returns null.
        public virtual string GetAppPoolID();
        //
        // Summary:
        //     Gets the number of bytes read in from the client.
        //
        // Returns:
        //     A Long containing the number of bytes read.
        public virtual long GetBytesRead();
        //
        // Summary:
        //     When overridden in a derived class, gets the certification fields (specified
        //     in the X.509 standard) from a request issued by the client.
        //
        // Returns:
        //     A byte array containing the stream of the entire certificate content.
        public virtual byte[] GetClientCertificate();
        //
        // Summary:
        //     Gets the certificate issuer, in binary format.
        //
        // Returns:
        //     A byte array containing the certificate issuer expressed in binary format.
        public virtual byte[] GetClientCertificateBinaryIssuer();
        //
        // Summary:
        //     When overridden in a derived class, returns the System.Text.Encoding object
        //     in which the client certificate was encoded.
        //
        // Returns:
        //     The certificate encoding, expressed as an integer.
        public virtual int GetClientCertificateEncoding();
        //
        // Summary:
        //     When overridden in a derived class, gets a PublicKey object associated with
        //     the client certificate.
        //
        // Returns:
        //     A PublicKey object.
        public virtual byte[] GetClientCertificatePublicKey();
        //
        // Summary:
        //     When overridden in a derived class, gets the date when the certificate becomes
        //     valid. The date varies with international settings.
        //
        // Returns:
        //     A System.DateTime object representing when the certificate becomes valid.
        public virtual DateTime GetClientCertificateValidFrom();
        //
        // Summary:
        //     Gets the certificate expiration date.
        //
        // Returns:
        //     A System.DateTime object representing the date that the certificate expires.
        public virtual DateTime GetClientCertificateValidUntil();
        //
        // Summary:
        //     When overridden in a derived class, returns the ID of the current connection.
        //
        // Returns:
        //     Always returns 0.
        public virtual long GetConnectionID();
        //
        // Summary:
        //     When overridden in a derived class, returns the virtual path to the requested
        //     URI.
        //
        // Returns:
        //     The path to the requested URI.
        public virtual string GetFilePath();
        //
        // Summary:
        //     Returns the physical file path to the requested URI (and translates it from
        //     virtual path to physical path: for example, "/proj1/page.aspx" to "c:\dir\page.aspx")
        //
        // Returns:
        //     The translated physical file path to the requested URI.
        public virtual string GetFilePathTranslated();
        //
        // Summary:
        //     Returns the specified member of the request header.
        //
        // Returns:
        //     The HTTP verb returned in the request header.
        public abstract string GetHttpVerbName();
        //
        // Summary:
        //     Provides access to the HTTP version of the request (for example, "HTTP/1.1").
        //
        // Returns:
        //     The HTTP version returned in the request header.
        public abstract string GetHttpVersion();
        //
        // Summary:
        //     Returns the standard HTTP request header that corresponds to the specified
        //     index.
        //
        // Parameters:
        //   index:
        //     The index of the header. For example, the System.Web.HttpWorkerRequest.HeaderAllow
        //     field.
        //
        // Returns:
        //     The HTTP request header.
        public virtual string GetKnownRequestHeader(int index);
        //
        // Summary:
        //     Returns the index number of the specified HTTP request header.
        //
        // Parameters:
        //   header:
        //     The name of the header.
        //
        // Returns:
        //     The index number of the HTTP request header specified in the header parameter.
        public static int GetKnownRequestHeaderIndex(string header);
        //
        // Summary:
        //     Returns the name of the specified HTTP request header.
        //
        // Parameters:
        //   index:
        //     The index number of the header.
        //
        // Returns:
        //     The name of the HTTP request header specified in the index parameter.
        public static string GetKnownRequestHeaderName(int index);
        //
        // Summary:
        //     Returns the index number of the specified HTTP response header.
        //
        // Parameters:
        //   header:
        //     The name of the HTTP header.
        //
        // Returns:
        //     The index number of the HTTP response header specified in the header parameter.
        public static int GetKnownResponseHeaderIndex(string header);
        //
        // Summary:
        //     Returns the name of the specified HTTP response header.
        //
        // Parameters:
        //   index:
        //     The index number of the header.
        //
        // Returns:
        //     The name of the HTTP response header specified in the index parameter.
        public static string GetKnownResponseHeaderName(int index);
        //
        // Summary:
        //     Provides access to the specified member of the request header.
        //
        // Returns:
        //     The server IP address returned in the request header.
        public abstract string GetLocalAddress();
        //
        // Summary:
        //     Provides access to the specified member of the request header.
        //
        // Returns:
        //     The server port number returned in the request header.
        public abstract int GetLocalPort();
        //
        // Summary:
        //     Returns additional path information for a resource with a URL extension.
        //     That is, for the path /virdir/page.html/tail, the GetPathInfo value is /tail.
        //
        // Returns:
        //     Additional path information for a resource.
        public virtual string GetPathInfo();
        //
        // Summary:
        //     Returns the portion of the HTTP request body that has already been read.
        //
        // Returns:
        //     The portion of the HTTP request body that has been read.
        public virtual byte[] GetPreloadedEntityBody();
        //
        // Summary:
        //     Gets the portion of the HTTP request body that has currently been read by
        //     using the specified buffer data and byte offset.
        //
        // Parameters:
        //   buffer:
        //     The data to read.
        //
        //   offset:
        //     The byte offset at which to begin reading.
        //
        // Returns:
        //     The portion of the HTTP request body that has been read.
        public virtual int GetPreloadedEntityBody(byte[] buffer, int offset);
        //
        // Summary:
        //     Gets the length of the portion of the HTTP request body that has currently
        //     been read.
        //
        // Returns:
        //     An integer containing the length of the currently read HTTP request body.
        public virtual int GetPreloadedEntityBodyLength();
        //
        // Summary:
        //     When overridden in a derived class, returns the HTTP protocol (HTTP or HTTPS).
        //
        // Returns:
        //     HTTPS if the System.Web.HttpWorkerRequest.IsSecure() method is true, otherwise
        //     HTTP.
        public virtual string GetProtocol();
        //
        // Summary:
        //     Returns the query string specified in the request URL.
        //
        // Returns:
        //     The request query string.
        public abstract string GetQueryString();
        //
        // Summary:
        //     When overridden in a derived class, returns the response query string as
        //     an array of bytes.
        //
        // Returns:
        //     An array of bytes containing the response.
        public virtual byte[] GetQueryStringRawBytes();
        //
        // Summary:
        //     Returns the URL path contained in the request header with the query string
        //     appended.
        //
        // Returns:
        //     The raw URL path of the request header.
        public abstract string GetRawUrl();
        //
        // Summary:
        //     Provides access to the specified member of the request header.
        //
        // Returns:
        //     The client‘s IP address.
        public abstract string GetRemoteAddress();
        //
        // Summary:
        //     When overridden in a derived class, returns the name of the client computer.
        //
        // Returns:
        //     The name of the client computer.
        public virtual string GetRemoteName();
        //
        // Summary:
        //     Provides access to the specified member of the request header.
        //
        // Returns:
        //     The client‘s HTTP port number.
        public abstract int GetRemotePort();
        //
        // Summary:
        //     When overridden in a derived class, returns the reason for the request.
        //
        // Returns:
        //     Reason code. The default is ReasonResponseCacheMiss.
        public virtual int GetRequestReason();
        //
        // Summary:
        //     When overridden in a derived class, returns the name of the local server.
        //
        // Returns:
        //     The name of the local server.
        public virtual string GetServerName();
        //
        // Summary:
        //     Returns a single server variable from a dictionary of server variables associated
        //     with the request.
        //
        // Parameters:
        //   name:
        //     The name of the requested server variable.
        //
        // Returns:
        //     The requested server variable.
        public virtual string GetServerVariable(string name);
        //
        // Summary:
        //     Returns a string that describes the name of the specified HTTP status code.
        //
        // Parameters:
        //   code:
        //     The HTTP status code.
        //
        // Returns:
        //     The status description. For example, System.Web.HttpWorkerRequest.GetStatusDescription(System.Int32)
        //     (404) returns "Not Found".
        public static string GetStatusDescription(int code);
        //
        // Summary:
        //     Gets the length of the entire HTTP request body.
        //
        // Returns:
        //     An integer containing the length of the entire HTTP request body.
        public virtual int GetTotalEntityBodyLength();
        //
        // Summary:
        //     Returns a nonstandard HTTP request header value.
        //
        // Parameters:
        //   name:
        //     The header name.
        //
        // Returns:
        //     The header value.
        public virtual string GetUnknownRequestHeader(string name);
        //
        // Summary:
        //     Get all nonstandard HTTP header name-value pairs.
        //
        // Returns:
        //     An array of header name-value pairs.
        [CLSCompliant(false)]
        public virtual string[][] GetUnknownRequestHeaders();
        //
        // Summary:
        //     Returns the virtual path to the requested URI.
        //
        // Returns:
        //     The path to the requested URI.
        public abstract string GetUriPath();
        //
        // Summary:
        //     When overridden in a derived class, returns the context ID of the current
        //     connection.
        //
        // Returns:
        //     Always returns 0.
        public virtual long GetUrlContextID();
        //
        // Summary:
        //     When overridden in a derived class, returns the client‘s impersonation token.
        //
        // Returns:
        //     A value representing the client‘s impersonation token. The default is 0.
        public virtual IntPtr GetUserToken();
        //
        // Summary:
        //     Gets the impersonation token for the request virtual path.
        //
        // Returns:
        //     An unmanaged memory pointer for the token for the request virtual path.
        public virtual IntPtr GetVirtualPathToken();
        //
        // Summary:
        //     Returns a value indicating whether the request contains body data.
        //
        // Returns:
        //     true if the request contains body data; otherwise, false.
        public bool HasEntityBody();
        //
        // Summary:
        //     Returns a value indicating whether HTTP response headers have been sent to
        //     the client for the current request.
        //
        // Returns:
        //     true if HTTP response headers have been sent to the client; otherwise, false.
        public virtual bool HeadersSent();
        //
        // Summary:
        //     Returns a value indicating whether the client connection is still active.
        //
        // Returns:
        //     true if the client connection is still active; otherwise, false.
        public virtual bool IsClientConnected();
        //
        // Summary:
        //     Returns a value indicating whether all request data is available and no further
        //     reads from the client are required.
        //
        // Returns:
        //     true if all request data is available; otherwise, false.
        public virtual bool IsEntireEntityBodyIsPreloaded();
        //
        // Summary:
        //     Returns a value indicating whether the connection uses SSL.
        //
        // Returns:
        //     true if the connection is an SSL connection; otherwise, false. The default
        //     is false.
        public virtual bool IsSecure();
        //
        // Summary:
        //     Returns the physical path corresponding to the specified virtual path.
        //
        // Parameters:
        //   virtualPath:
        //     The virtual path.
        //
        // Returns:
        //     The physical path that corresponds to the virtual path specified in the virtualPath
        //     parameter.
        public virtual string MapPath(string virtualPath);
        //
        // Summary:
        //     Reads request data from the client (when not preloaded).
        //
        // Parameters:
        //   buffer:
        //     The byte array to read data into.
        //
        //   size:
        //     The maximum number of bytes to read.
        //
        // Returns:
        //     The number of bytes read.
        public virtual int ReadEntityBody(byte[] buffer, int size);
        //
        // Summary:
        //     Reads request data from the client (when not preloaded) by using the specified
        //     buffer to read from, byte offset, and maximum bytes.
        //
        // Parameters:
        //   buffer:
        //     The byte array to read data into.
        //
        //   offset:
        //     The byte offset at which to begin reading.
        //
        //   size:
        //     The maximum number of bytes to read.
        //
        // Returns:
        //     The number of bytes read.
        public virtual int ReadEntityBody(byte[] buffer, int offset, int size);
        //
        // Summary:
        //     Adds a Content-Length HTTP header to the response for message bodies that
        //     are less than or equal to 2 GB.
        //
        // Parameters:
        //   contentLength:
        //     The length of the response, in bytes.
        public virtual void SendCalculatedContentLength(int contentLength);
        //
        // Summary:
        //     Adds a Content-Length HTTP header to the response for message bodies that
        //     are greater than 2 GB.
        //
        // Parameters:
        //   contentLength:
        //     The length of the response, in bytes.
        public virtual void SendCalculatedContentLength(long contentLength);
        //
        // Summary:
        //     Adds a standard HTTP header to the response.
        //
        // Parameters:
        //   index:
        //     The header index. For example, System.Web.HttpWorkerRequest.HeaderContentLength.
        //
        //   value:
        //     The value of the header.
        public abstract void SendKnownResponseHeader(int index, string value);
        //
        // Summary:
        //     Adds the contents of the specified file to the response and specifies the
        //     starting position in the file and the number of bytes to send.
        //
        // Parameters:
        //   handle:
        //     The handle of the file to send.
        //
        //   offset:
        //     The starting position in the file.
        //
        //   length:
        //     The number of bytes to send.
        public abstract void SendResponseFromFile(IntPtr handle, long offset, long length);
        //
        // Summary:
        //     Adds the contents of the specified file to the response and specifies the
        //     starting position in the file and the number of bytes to send.
        //
        // Parameters:
        //   filename:
        //     The name of the file to send.
        //
        //   offset:
        //     The starting position in the file.
        //
        //   length:
        //     The number of bytes to send.
        public abstract void SendResponseFromFile(string filename, long offset, long length);
        //
        // Summary:
        //     Adds the specified number of bytes from a byte array to the response.
        //
        // Parameters:
        //   data:
        //     The byte array to send.
        //
        //   length:
        //     The number of bytes to send, starting at the first byte.
        public abstract void SendResponseFromMemory(byte[] data, int length);
        //
        // Summary:
        //     Adds the specified number of bytes from a block of memory to the response.
        //
        // Parameters:
        //   data:
        //     An unmanaged pointer to the block of memory.
        //
        //   length:
        //     The number of bytes to send.
        public virtual void SendResponseFromMemory(IntPtr data, int length);
        //
        // Summary:
        //     Specifies the HTTP status code and status description of the response, such
        //     as SendStatus(200, "Ok").
        //
        // Parameters:
        //   statusCode:
        //     The status code to send
        //
        //   statusDescription:
        //     The status description to send.
        public abstract void SendStatus(int statusCode, string statusDescription);
        //
        // Summary:
        //     Adds a nonstandard HTTP header to the response.
        //
        // Parameters:
        //   name:
        //     The name of the header to send.
        //
        //   value:
        //     The value of the header.
        public abstract void SendUnknownResponseHeader(string name, string value);
        //
        // Summary:
        //     Registers for an optional notification when all the response data is sent.
        //
        // Parameters:
        //   callback:
        //     The notification callback that is called when all data is sent (out-of-band).
        //
        //   extraData:
        //     An additional parameter to the callback.
        public virtual void SetEndOfSendNotification(HttpWorkerRequest.EndOfSendNotification callback, object extraData);

        // Summary:
        //     Represents the method that Notifies callers when sending of the response
        //     is complete.
        //
        // Parameters:
        //   wr:
        //     The current System.Web.HttpWorkerRequest.
        //
        //   extraData:
        //     Any additional data needed to process the request.
        public delegate void EndOfSendNotification(HttpWorkerRequest wr, object extraData);
    }
}

该类是一个很底层的类,主要用于asp.net服务器内部,在一些特殊情况下,可以完成一些特殊的任务,比如,上传文件时,默认情况下,asp.net会将上传的文件内容读取到服务器的内存中,然后通过控件的方式供我们使用。这种在上传小文件的时候很方便,大文件的时候,服务器内存将出现问题,导致浏览器不能将文件继续传输。浏览器将显示“The page cannot be displayed -cannot find server or dns error.”,这个错误无法在服务器端进行捕获或者处理。

借助HttpWorkerRequest的GetPreloadedEntityBody和ReadEntityBody方法,我们可以自己分块从客户端读取上传的文件内容。然后将内容保存在一个临时文件中.

SlickUpload组件,就是基于这个实现的。感兴趣的可以看看这篇文章,如何使用该组件。

http://blog.csdn.net/zhoufoxcn/article/details/5765748

下载源码

http://slickupload.com/

时间: 2024-10-25 09:09:28

工作者对象HttpWorkerRequest的相关文章

对象化的Http和请求对象HttpRequest

在面向对象的语言中,有种“万物皆对象”的说法.在上篇文章中介绍了HttpRuntime类,在该类收到请求之后,立即通过HttpWorkerRequest工作者对象对传递的参数进行分析和分解,创建方便网站应用程序处理的对象.与此相关的对象主要有,请求和响应两个对象.即HttpRequest和HttpResponse类型. HttpRequest定义在命名空间System.Web下 // Summary: // Enables ASP.NET to read the HTTP values sent

1.网站应用程序 - 《APS.NET本质论》

1.1.HTTP协议 浏览器与WEB服务器的协议是应用层协议,当前遵循HTTP/1.1,HTTP协议是无状态的协议 客户机与服务器通过请求和响应完成一次会话(Session),每次会话中,双方发送的数据称为消息(Message),消息分为两种: 请求消息和回应消息. 客户端请求消息 客户端发送一个HTTP请求到服务器的请求消息包括以下格式:请求行(request line).请求头部(header).空行和请求数据四个部分组成,下图给出了请求报文的一般格式. 服务器响应消息 HTTP响应也由四个

ASP.NET那点不为人知的事(一)

http://www.cnblogs.com/OceanEyes/archive/2012/08/13/aspnetEssential-1.html#_label0 我们上网时,在浏览器地址输入网址:Http://www.cnblogs.com,按下回车,一张网页就呈现在我们眼前.这究竟发生了什么?对于一名优秀的Programmer来说,我想有必要一下熟悉浏览器--->服务器请求的过程. 回到顶部 ASP.NET ASP.NET是运行在公共语言运行时刻时(CLR)上的应用程序框架.他用来在服务器

第一章 网站应用程序

System.URI 常用属性: Scheme 协议名称 Host 主机 Port 端口 AbsoultePath 绝对路径 Query URI地址中的参数部分 URI(通用资源标识符) URL(统一资源定位符) 为IP取一个有意义的名字就是域名,通过DNS(域名服务器)来关联IP和域名程序与程序的通信层次 1.物理层 2.数据链路层 3.网络层 4.传输层 5.会话层 6.表示层 7.应用层 应用层协议的内容需要通过传输层在浏览器和服务器之间进行传送 TCP/IP中 TCP负责可靠通信的传输层

自实现简单线程池

线程池在现在的系统和框架中十分常见.明白线程池的思想原理,不仅对学习线程只是有很大的帮助.对理解一些系统的线程池实现也有很大的帮助.下面是我自己简单实现的一个线程池.用以对线程的简单理解. 线程的实现原理很简单: 线程池对象包含以下组件:工作者队列,Job队列: 用户通过线程池对象添加删除工作者,线程池对象维持工作者对象这个池和工作者的实际工作: 工作者池中的线程在用户没用明确关闭前不断的从Job队列拿取job执行job. 好了,一切看代码: 1.以接口编程,首先创建ThreadPool接口:

Qt - QThread(翻译帮助文档)

QThread Class 详细描述 QThread 类提供一个平台无关的方法来管理线程. 一个QThread对象管理一个程序中的控制线程.QThread在run()中开始执行任务.默认地,run()通过调用exec()开始事件循环,并且在线程中运行Qt事件循环. 你可通过使用QObject::moveToThread()将worker对象移到线程中来使用worker对象. class Worker : public QObject { Q_OBJECT public slots: void d

Qt 线程基础

(转自:http://my.oschina.net/laopiao/blog/88158) 保谓线程? 线程与并行处理任务息息相关,就像进程一样.那么,线程与进程有什么区别呢?当你在电子表格上进行数据结算的时候,在相同的桌面上可能有一个播放器正在播放你最喜欢的歌曲.这是一个两个进程并行工作的例子:一个进程运行电子表格程序;另一个进程运行一个媒体播放器.这种情况最适合用多任务这个词来描述.进一步观察媒体播放器,你会发现在这个进程内,又存在并行的工作.当媒体播放器向音频驱动发送音乐数据的时候,用户界

基于.NET 框架的 通信组件ZMQ完整教程-总目录

ZMQ是一个比较轻量级的消息通信组件,引用官方的说法: "ZMQ (以下 ZeroMQ 简称 ZMQ)是一个简单好用的传输层,像框架一样的一个 socket library,他使得 Socket 编程更加简单.简洁和性能更高.是一个消息处理队列库,可在多个线程.内核和主机盒之间弹性伸缩.ZMQ 的明确目标是"成为标准网络协议栈的一部分,之后进入 Linux 内核".现在还未看到它们的成功.但是,它无疑是极具前景的.并且是人们更加需要的"传统"BSD 套接字

QThread与多线程(比较清楚)

QThread类为我们提供了一种平台无关的管理线程的方式.一个QThread对象管理应用程序中的一个线程,该线程从run()函数开始执行.并且,默认情况下,我们可以在run()函数中通过调用QThread::exec()函数来在当前线程中开启一个事件循环. 而使用QThread开启线程的最常用的方式 就是继承QThread类,重写其run()方法,因为我们刚才就说过,QThread代表的线程就是从run()函数开始运行的. 例如: class WorkerThread : public QThr