艾伟_转载:HttpRuntime的认识与加深理解

下面最先介绍HttpRuntime的Web.config里的配置

<httpRuntime
   executionTimeout = "number" 
   maxRequestLength = "number" 
   requestLengthDiskThreshold = "number" 
   useFullyQualifiedRedirectUrl = "[True|False]" 
   minFreeThreads = "number" 
   minLocalRequestFreeThreads = "number" 
   appRequestQueueLimit = "number"
   enableKernelOutputCache = "[True|False]" 
   enableVersionHeader = "[True|False]" 
   apartmentThreading = "[True|False]"
   requireRootedSaveAsPath = "[True|False]"
   enable = "[True|False]" 
   sendCacheControlHeader = "[True|False]" 
   shutdownTimeout = "number"
   delayNotificationTimeout = "number"
   waitChangeNotification = "number" 
   maxWaitChangeNotification = "number" 
   enableHeaderChecking = "[True|False]" 
/>

通过上面的配置说明, 下面是在Web.Config里节点的设置

<configuration>
  <system.web>
  <httpRuntime maxRequestLength="4000"
    enable = "True"
    requestLengthDiskThreshold="512
    useFullyQualifiedRedirectUrl="True"
    executionTimeout="45"
    versionHeader="1.1.4128"/>
  system.web>
configuration>

IIS 所收到的对某 Microsoft ASP.NET 页面的每个请求都被移交给 ASP.NET HTTP 管线。HTTP 管线由一系列托管对象组成,这些对象按顺序处理该请求,并完成从 URL 到普通 HTML 文本的转换。HTTP 管线的入口点是 HttpRuntime 类。ASP.NET 基础结构为辅助进程中所承载的每个 AppDomain 创建此类的一个实例请注意,该辅助进程为当前正在运行的每个 ASP.NET 应用程序维护一个不同的 AppDomain。

要激活 HTTP 管道,可以创建一个 HttpRuntime 类的新实例,然后调用其 ProcessRequest 方法。一个完整的页面请求会包括下面的流程:
首先被WWW服务器截获(inetinfo.exe进程), 该进程首先判断页面后缀, 然后根据IIS中配置决定调用具体的扩展程序。aspx就会调用aspnet_isapi.dll,
然后由aspnet_isapi.dll发送给w3wp.exe(iis 工作者进程,IIS6.0中叫做 w3wq.exe,IIS5.0中叫做 aspnet_wp.exe)。

接下来在w3wp.exe调用.NET类库进行具体处理,顺序如下:ISAPIRuntim, HttpRuntime, HttpApplicationFactory, HttpApplication, HttpModule, HttpHandlerFactory, HttpHandler

ISAPIRuntime:主要作用是调用一些非托管代码生成HttpWorkerRequest对象,HttpWorkerRequest对象包含当前请求的所有信息,然后传递给HttpRuntime
HttpRuntime:根据HttpWorkerRequest对象生成HttpContext,HttpContext包含request、response等属性, 再调用HttpApplicationFactory来生成IHttpHandler, 调用HttpApplication对象执行请求
HttpApplicationFactory: 生成一个HttpApplication对象
HttpApplication:进行HttpModule的初始化,HttpApplication创建针对此Http请求的 HttpContext对象
HttpModule: 当一个HTTP请求到达HttpModule时,整个ASP.NET Framework系统还并没有对这个HTTP请求做任何处理,也就是说此时对于HTTP请求来讲,HttpModule是一个HTTP请求的“必经之路”,所以可以在这个HTTP请求传递到真正的请求处理中心(HttpHandler)之前附加一些需要的信息在这个HTTP请求信息之上,或者针对截获的这个HTTP请求信息作一些额外的工作,或者在某些情况下干脆终止满足一些条件的HTTP请求,从而可以起到一个Filter过滤器的作用。
HttpHandlerFactory:把用户request 转发到HttpHandlerFactory,再由HttpHandlerFactory实例化HttpHandler对象来相应request
HttpHandle:Http处理程序,处理页面请求

从上面看出HttpRuntime其中有一个ProcessRequest 方法
public static void ProcessRequest(HttpWorkerRequest wr);  //驱动所有 ASP.NET Web 处理执行。伪代码如下:

public static void HttpRuntime.ProcessRequest(HttpWorkerRequest wr)
 {
   // 检查当前调用者有没有作为ASP.NET宿主(Host)的权限
   InternalSecurityPermissions.AspNetHostingPermissionLevelMedium.Demand(); 

   if(wr == null)
   {
     throw new ArgumentNullException("custom");
   }

   RequestQueue queue = HttpRuntime._theRuntime._requestQueue;

   if(queue != null)
   {
     // 将参数中的Web页面请求放入请求队列中, 并从队列中使用FIFO策略获取一个页面请求
     wr = queue.GetRequestToExecute(wr);
   }

   if(wr != null)
   {     
     HttpRuntime.CalculateWaitTimeAndUpdatePerfCounter(wr); // 更新性能计数器     
      HttpRuntime.ProcessRequestNow(wr); // 实际完成页面请求工作
   }
 }

ProcessRequestNow函数则直接调用缺省HttpRuntime实例的ProcessRequestInternal函数完成实际页面请求工作,伪代码如下:

internal static void HttpRuntime.ProcessRequestNow(HttpWorkerRequest wr)
{
   HttpRuntime._theRuntime.ProcessRequestInternal(wr);
}

ProcessRequestInternal函数逻辑稍微复杂一些,大致可分为四个部分:
检查当前HttpRuntime实例是否第一次被调用,如果是第一次调用则通过FirstRequestInit函数初始化
调用HttpResponse.InitResponseWriter函数初始化页面请求的返回对象HttpWorkerRequest.Response
调用HttpApplicationFactory.GetApplicationInstance函数获取当前 Web 应用程序实例
使用Web应用程序实例完成实际的页面请求工作
伪代码如下:

Code
private void HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
 {
   // 构造 HTTP 调用上下文对象
   HttpContext ctxt = new HttpContext(wr, 0); 

   // 设置发送结束异步回调函数
   wr.SetEndOfSendNotification(this._asyncEndOfSendCallback, ctxt);

   // 更新请求计数器
   Interlocked.Increment(&(this._activeRequestCount));

   try
   {
     // 检查当前HttpRuntime实例是否第一次被调用
     if(this._beforeFirstRequest)
     {
       lock(this)
       {
         // 使用 Double-Checked 模式 避免冗余锁定
         if(this._beforeFirstRequest)
         {
           this._firstRequestStartTime = DateTime.UtcNow;
           this.FirstRequestInit(ctxt); // 初始化当前 HttpRuntime 运行时环境
           this._beforeFirstRequest = false;
         }
       }
     }

     // 根据配置文件设置,扮演具有较高特权的角色
     ctxt.Impersonation.Start(true, false);
     try
     {
       // 初始化页面请求的返回对象
       ctxt.Response.InitResponseWriter();
     }
     finally
     {
       ctxt.Impersonation.Stop();
     }

     // 获取当前 Web 应用程序实例
     IHttpHandler handler = HttpApplicationFactory.GetApplicationInstance(ctxt);

     if (handler == null)
     {
       throw new HttpException(HttpRuntime.FormatResourceString("Unable_create_app_object"));
     }

     // 使用Web应用程序实例完成实际的页面请求工作
     if((handler as IHttpAsyncHandler) != null)
     {
       IHttpAsyncHandler asyncHandler = ((IHttpAsyncHandler) handler);
       ctxt.AsyncAppHandler = asyncHandler;
       // 使用异步处理机制
       asyncHandler.BeginProcessRequest(ctxt, this._handlerCompletionCallback, ctxt);
     }
     else
     {
       handler.ProcessRequest(ctxt);
       this.FinishRequest(ctxt.WorkerRequest, ctxt, null);
     }
   }
   catch(Exception E)
   {
     ctxt.Response.InitResponseWriter();
     this.FinishRequest(wr, ctxt, E);
   }
 }

HttpRuntime.ProcessRequestInternal函数中调用了HttpApplicationFactory.GetApplicationInstance函数获取当前 Web 应用程序实例。至少HttpRuntime已经完完成,将转进HttpApplicationFactory阶段流程。大家可以看到,围绕HttpRuntime的函数都有一个HttpWorkerRequest参数,下面简单介绍一下这个参数的作用。在ISAPIRuntime阶段,调用一些非托管代码生成HttpWorkerRequest对象,该对象包含当前请求的所有信息,然后传递给HttpRuntime,这里生成的HttpWorkerRequest对象可以直接在我们的页面里调用.
IServiceProvider provider=(IServiceProvider)HttpContext.Current;
HttpWorkerRequest wr=(HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
然后可以通过wr来调用里面的方法。关于HttpWorkerRequest类里面包含的方法,从其元数据里面可以看到,如下:

Code
public abstract class HttpWorkerRequest
    {
        // 摘要:
        //     指定 AcceptHTTP 标头的索引号。
        public const int HeaderAccept = 20;
        //
        // 摘要:
        //     指定 Accept-CharsetHTTP 标头的索引号。
        public const int HeaderAcceptCharset = 21;
        //
        // 摘要:
        //     指定 Accept-EncodingHTTP 标头的索引号。
        public const int HeaderAcceptEncoding = 22;
        //
        // 摘要:
        //     指定 Accept-LanguageHTTP 标头的索引号。
        public const int HeaderAcceptLanguage = 23;
        //
        // 摘要:
        //     指定 Accept-RangesHTTP 标头的索引号。
        public const int HeaderAcceptRanges = 20;
        //
        // 摘要:
        //     指定 AgeHTTP 标头的索引号。
        public const int HeaderAge = 21;
        //
        // 摘要:
        //     指定 AllowHTTP 标头的索引号。
        public const int HeaderAllow = 10;
        //
        // 摘要:
        //     指定 AuthorizationHTTP 标头的索引号。
        public const int HeaderAuthorization = 24;
        //
        // 摘要:
        //     表示 HTTPCache-ControlHTTP 标头的索引。
        public const int HeaderCacheControl = 0;
        //
        // 摘要:
        //     指定 ConnectionHTTP 标头的索引号。
        public const int HeaderConnection = 1;
        //
        // 摘要:
        //     指定 Content-EncodingHTTP 标头的索引号。
        public const int HeaderContentEncoding = 13;
        //
        // 摘要:
        //     指定 Content-LanguageHTTP 标头的索引号。
        public const int HeaderContentLanguage = 14;
        //
        // 摘要:
        //     指定 Content-LengthHTTP 标头的索引号。
        public const int HeaderContentLength = 11;
        //
        // 摘要:
        //     指定 Content-LocationHTTP 标头的索引号。
        public const int HeaderContentLocation = 15;
        //
        // 摘要:
        //     指定 Content-MD5HTTP 标头的索引号。
        public const int HeaderContentMd5 = 16;
        //
        // 摘要:
        //     指定 Content-RangeHTTP 标头的索引号。
        public const int HeaderContentRange = 17;
        //
        // 摘要:
        //     指定 Content-TypeHTTP 标头的索引号。
        public const int HeaderContentType = 12;
        //
        // 摘要:
        //     指定 CookieHTTP 标头的索引号。
        public const int HeaderCookie = 25;
        //
        // 摘要:
        //     指定 DateHTTP 标头的索引号。
        public const int HeaderDate = 2;
        //
        // 摘要:
        //     指定 ETagHTTP 标头的索引号。
        public const int HeaderEtag = 22;
        //
        // 摘要:
        //     指定 ExceptHTTP 标头的索引号。
        public const int HeaderExpect = 26;
        //
        // 摘要:
        //     指定 ExpiresHTTP 标头的索引号。
        public const int HeaderExpires = 18;
        //
        // 摘要:
        //     指定 FromHTTP 标头的索引号。
        public const int HeaderFrom = 27;
        //
        // 摘要:
        //     指定 HostHTTP 标头的索引号。
        public const int HeaderHost = 28;
        //
        // 摘要:
        //     指定 If-MatchHTTP 标头的索引号。
        public const int HeaderIfMatch = 29;
        //
        // 摘要:
        //     指定 If-Modified-SinceHTTP 标头的索引号。
        public const int HeaderIfModifiedSince = 30;
        //
        // 摘要:
        //     指定 If-None-MatchHTTP 标头的索引号。
        public const int HeaderIfNoneMatch = 31;
        //
        // 摘要:
        //     指定 If-RangeHTTP 标头的索引号。
        public const int HeaderIfRange = 32;
        //
        // 摘要:
        //     指定 If-Unmodified-SinceHTTP 标头的索引号。
        public const int HeaderIfUnmodifiedSince = 33;
        //
        // 摘要:
        //     指定 Keep-AliveHTTP 标头的索引号。
        public const int HeaderKeepAlive = 3;
        //
        // 摘要:
        //     指定 Last-ModifiedHTTP 标头的索引号。
        public const int HeaderLastModified = 19;
        //
        // 摘要:
        //     指定 LocationHTTP 标头的索引号。
        public const int HeaderLocation = 23;
        //
        // 摘要:
        //     指定 Max-ForwardsHTTP 标头的索引号。
        public const int HeaderMaxForwards = 34;
        //
        // 摘要:
        //     指定 PragmaHTTP 标头的索引号。
        public const int HeaderPragma = 4;
        //
        // 摘要:
        //     指定 Proxy-AuthenticateHTTP 标头的索引号。
        public const int HeaderProxyAuthenticate = 24;
        //
        // 摘要:
        //     指定 Proxy-AuthorizationHTTP 标头的索引号。
        public const int HeaderProxyAuthorization = 35;
        //
        // 摘要:
        //     指定 RangeHTTP 标头的索引号。
        public const int HeaderRange = 37;
        //
        // 摘要:
        //     指定 RefererHTTP 标头的索引号。
        public const int HeaderReferer = 36;
        //
        // 摘要:
        //     指定 Retry-AfterHTTP 标头的索引号。
        public const int HeaderRetryAfter = 25;
        //
        // 摘要:
        //     指定 ServerHTTP 标头的索引号。
        public const int HeaderServer = 26;
        //
        // 摘要:
        //     指定 Set-CookieHTTP 标头的索引号。
        public const int HeaderSetCookie = 27;
        //
        // 摘要:
        //     指定 TEHTTP 标头的索引号。
        public const int HeaderTe = 38;
        //
        // 摘要:
        //     指定 TrailerHTTP 标头的索引号。
        public const int HeaderTrailer = 5;
        //
        // 摘要:
        //     指定 Transfer-EncodingHTTP 标头的索引号。
        public const int HeaderTransferEncoding = 6;
        //
        // 摘要:
        //     指定 UpgradeHTTP 标头的索引号。
        public const int HeaderUpgrade = 7;
        //
        // 摘要:
        //     指定 User-AgentHTTP 标头的索引号。
        public const int HeaderUserAgent = 39;
        //
        // 摘要:
        //     指定 VaryHTTP 标头的索引号。
        public const int HeaderVary = 28;
        //
        // 摘要:
        //     指定 ViaHTTP 标头的索引号。
        public const int HeaderVia = 8;
        //
        // 摘要:
        //     指定 WarningHTTP 标头的索引号。
        public const int HeaderWarning = 9;
        //
        // 摘要:
        //     指定 WWW-AuthenticateHTTP 标头的索引号。
        public const int HeaderWwwAuthenticate = 29;
        //
        // 摘要:
        //     指定请求的原因。
        public const int ReasonCachePolicy = 2;
        //
        // 摘要:
        //     指定请求的原因。
        public const int ReasonCacheSecurity = 3;
        //
        // 摘要:
        //     指定请求的原因。
        public const int ReasonClientDisconnect = 4;
        //
        // 摘要:
        //     指定请求的原因。默认值为 System.Web.HttpWorkerRequest.ReasonResponseCacheMiss。
        public const int ReasonDefault = 0;
        //
        // 摘要:
        //     指定请求的原因。
        public const int ReasonFileHandleCacheMiss = 1;
        //
        // 摘要:
        //     指定请求的原因。
        public const int ReasonResponseCacheMiss = 0;
        //
        // 摘要:
        //     指定 MaximumHTTP 请求标头的索引号。
        public const int RequestHeaderMaximum = 40;
        //
        // 摘要:
        //     指定 MaximumHTTP 响应标头的索引号。
        public const int ResponseHeaderMaximum = 30;

        // 摘要:
        //     初始化 System.Web.HttpWorkerRequest 类的新实例。
        protected HttpWorkerRequest();

        // 摘要:
        //     获取 Machine.config 文件的完整物理路径。
        //
        // 返回结果:
        //     Machine.config 文件的物理路径。
        public virtual string MachineConfigPath { get; }
        //
        // 摘要:
        //     获取 ASP.NET 二进制文件的安装目录的物理路径。
        //
        // 返回结果:
        //     ASP.NET 二进制文件的物理目录。
        public virtual string MachineInstallDirectory { get; }
        //
        // 摘要:
        //     获取当前请求的 Windows 跟踪 ID 的对应事件跟踪。
        //
        // 返回结果:
        //     当前 ASP.NET 请求的跟踪 ID。
        public virtual Guid RequestTraceIdentifier { get; }
        //
        // 摘要:
        //     获取根 Web.config 文件的完整物理路径。
        //
        // 返回结果:
        //     根 Web.config 文件的物理路径。
        public virtual string RootWebConfigPath { get; }

        // 摘要:
        //     终止与客户端的连接。
        public virtual void CloseConnection();
        //
        // 摘要:
        //     由运行库使用以通知 System.Web.HttpWorkerRequest 当前请求的请求处理已完成。
        public abstract void EndOfRequest();
        //
        // 摘要:
        //     将所有挂起的响应数据发送到客户端。
        //
        // 参数:
        //   finalFlush:
        //     如果这将是最后一次刷新响应数据,则为 true;否则为 false。
        public abstract void FlushResponse(bool finalFlush);
        //
        // 摘要:
        //     返回当前正在执行的服务器应用程序的虚拟路径。
        //
        // 返回结果:
        //     当前应用程序的虚拟路径。
        public virtual string GetAppPath();
        //
        // 摘要:
        //     返回当前正在执行的服务器应用程序的物理路径。
        //
        // 返回结果:
        //     当前应用程序的物理路径。
        public virtual string GetAppPathTranslated();
        //
        // 摘要:
        //     在派生类中被重写时,返回当前 URL 的应用程序池 ID。
        //
        // 返回结果:
        //     始终返回 null。
        public virtual string GetAppPoolID();
        //
        // 摘要:
        //     获取从客户端读入的字节数。
        //
        // 返回结果:
        //     包含读取的字节数的 Long。
        public virtual long GetBytesRead();
        //
        // 摘要:
        //     在派生类中被重写时,从客户端发出的请求获取证书字段(以 X.509 标准指定)。
        //
        // 返回结果:
        //     包含整个证书内容流的字节数组。
        public virtual byte[] GetClientCertificate();
        //
        // 摘要:
        //     获取证书颁发者(以二进制格式表示)。
        //
        // 返回结果:
        //     包含以二进制格式表示的证书颁发者的字节数组。
        public virtual byte[] GetClientCertificateBinaryIssuer();
        //
        // 摘要:
        //     在派生类中被重写时,返回用于编码客户端证书的 System.Text.Encoding 对象。
        //
        // 返回结果:
        //     表示为整数的证书编码。
        public virtual int GetClientCertificateEncoding();
        //
        // 摘要:
        //     在派生类中被重写时,获取与客户端证书关联的 PublicKey 对象。
        //
        // 返回结果:
        //     一个 PublicKey 对象。
        public virtual byte[] GetClientCertificatePublicKey();
        //
        // 摘要:
        //     在派生类中被重写时,则获取证书开始生效的日期。此日期随区域设置的不同而不同。
        //
        // 返回结果:
        //     表示证书生效时间的 System.DateTime 对象。
        public virtual DateTime GetClientCertificateValidFrom();
        //
        // 摘要:
        //     获取证书到期日期。
        //
        // 返回结果:
        //     表示证书失效日期的 System.DateTime 对象。
        public virtual DateTime GetClientCertificateValidUntil();
        //
        // 摘要:
        //     在派生类中被重写时,返回当前连接的 ID。
        //
        // 返回结果:
        //     始终返回 0。
        public virtual long GetConnectionID();
        //
        // 摘要:
        //     在派生类中被重写时,返回所请求的 URI 的虚拟路径。
        //
        // 返回结果:
        //     请求的 URI 的路径。
        public virtual string GetFilePath();
        //
        // 摘要:
        //     返回请求的 URI 的物理文件路径(并将其从虚拟路径转换成物理路径:例如,从“/proj1/page.aspx”转换成“c:\dir\page.aspx”)
        //
        // 返回结果:
        //     请求的 URI 的已转换的物理文件路径。
        public virtual string GetFilePathTranslated();
        //
        // 摘要:
        //     返回请求标头的指定成员。
        //
        // 返回结果:
        //     请求标头中返回的 HTTP 谓词。
        public abstract string GetHttpVerbName();
        //
        // 摘要:
        //     提供对请求的 HTTP 版本(如“HTTP/1.1”)的访问。
        //
        // 返回结果:
        //     请求标头中返回的 HTTP 版本。
        public abstract string GetHttpVersion();
        //
        // 摘要:
        //     返回与指定的索引相对应的标准 HTTP 请求标头。
        //
        // 参数:
        //   index:
        //     标头的索引。例如,System.Web.HttpWorkerRequest.HeaderAllow 字段。
        //
        // 返回结果:
        //     HTTP 请求标头。
        public virtual string GetKnownRequestHeader(int index);
        //
        // 摘要:
        //     返回指定的 HTTP 请求标头的索引号。
        //
        // 参数:
        //   header:
        //     标头的名称。
        //
        // 返回结果:
        //     在 header 参数中指定的 HTTP 请求标头的索引号。
        public static int GetKnownRequestHeaderIndex(string header);
        //
        // 摘要:
        //     返回指定的 HTTP 请求标头的名称。
        //
        // 参数:
        //   index:
        //     标头的索引号。
        //
        // 返回结果:
        //     在 index 参数中指定的 HTTP 请求标头的名称。
        public static string GetKnownRequestHeaderName(int index);
        //
        // 摘要:
        //     返回指定的 HTTP 响应标头的索引号。
        //
        // 参数:
        //   header:
        //     HTTP 标头的名称。
        //
        // 返回结果:
        //     在 header 参数中指定的 HTTP 响应标头的索引号。
        public static int GetKnownResponseHeaderIndex(string header);
        //
        // 摘要:
        //     返回指定的 HTTP 响应标头的名称。
        //
        // 参数:
        //   index:
        //     标头的索引号。
        //
        // 返回结果:
        //     在 index 参数中指定的 HTTP 响应标头的名称。
        public static string GetKnownResponseHeaderName(int index);
        //
        // 摘要:
        //     提供对请求标头的指定成员的访问。
        //
        // 返回结果:
        //     请求标头中返回的服务器 IP 地址。
        public abstract string GetLocalAddress();
        //
        // 摘要:
        //     提供对请求标头的指定成员的访问。
        //
        // 返回结果:
        //     请求标头中返回的服务器端口号。
        public abstract int GetLocalPort();
        //
        // 摘要:
        //     返回具有 URL 扩展的资源的其他路径信息。即对于路径 /virdir/page.html/tail,GetPathInfo 值为 /tail。
        //
        // 返回结果:
        //     资源的附加路径信息。
        public virtual string GetPathInfo();
        //
        // 摘要:
        //     返回 HTTP 请求正文已被读取的部分。
        //
        // 返回结果:
        //     HTTP 请求正文已被读取的部分。
        public virtual byte[] GetPreloadedEntityBody();
        //
        // 摘要:
        //     使用指定的缓冲区数据和字节偏移量获取 HTTP 请求正文当前已被读取的部分。
        //
        // 参数:
        //   buffer:
        //     要读取的数据。
        //
        //   offset:
        //     开始读取的位置的字节偏移量。
        //
        // 返回结果:
        //     HTTP 请求正文已被读取的部分。
        public virtual int GetPreloadedEntityBody(byte[] buffer, int offset);
        //
        // 摘要:
        //     获取 HTTP 请求正文当前已被读取部分的长度。
        //
        // 返回结果:
        //     一个整数,包含当前已读取的 HTTP 请求正文的长度。
        public virtual int GetPreloadedEntityBodyLength();
        //
        // 摘要:
        //     在派生类中被重写时,返回 HTTP 协议(HTTP 或 HTTPS)。
        //
        // 返回结果:
        //     如果 System.Web.HttpWorkerRequest.IsSecure() 方法为 true,则为 HTTPS;否则,为 HTTP。
        public virtual string GetProtocol();
        //
        // 摘要:
        //     返回请求 URL 中指定的查询字符串。
        //
        // 返回结果:
        //     请求查询字符串。
        public abstract string GetQueryString();
        //
        // 摘要:
        //     在派生类中被重写时,以字节数组的形式返回响应查询字符串。
        //
        // 返回结果:
        //     包含响应的字节数组。
        public virtual byte[] GetQueryStringRawBytes();
        //
        // 摘要:
        //     返回附加了查询字符串的请求标头中包含的 URL 路径。
        //
        // 返回结果:
        //     请求标头的原始 URL 路径。
        public abstract string GetRawUrl();
        //
        // 摘要:
        //     提供对请求标头的指定成员的访问。
        //
        // 返回结果:
        //     客户端的 IP 地址。
        public abstract string GetRemoteAddress();
        //
        // 摘要:
        //     在派生类中被重写时,返回客户端计算机的名称。
        //
        // 返回结果:
        //     客户端计算机的名称。
        public virtual string GetRemoteName();
        //
        // 摘要:
        //     提供对请求标头的指定成员的访问。
        //
        // 返回结果:
        //     客户端的 HTTP 端口号。
        public abstract int GetRemotePort();
        //
        // 摘要:
        //     在派生类中被重写时,返回请求的原因。
        //
        // 返回结果:
        //     原因代码。默认值为 ReasonResponseCacheMiss。
        public virtual int GetRequestReason();
        //
        // 摘要:
        //     在派生类中被重写时,返回本地服务器的名称。
        //
        // 返回结果:
        //     本地服务器的名称。
        public virtual string GetServerName();
        //
        // 摘要:
        //     从与请求关联的服务器变量词典返回单个服务器变量。
        //
        // 参数:
        //   name:
        //     请求的服务器变量的名称。
        //
        // 返回结果:
        //     请求的服务器变量。
        public virtual string GetServerVariable(string name);
        //
        // 摘要:
        //     返回一个字符串,该字符串描述指定的 HTTP 状态代码的名称。
        //
        // 参数:
        //   code:
        //     HTTP 状态代码。
        //
        // 返回结果:
        //     状态说明。例如,System.Web.HttpWorkerRequest.GetStatusDescription(System.Int32) (404)
        //     返回“未找到”。
        public static string GetStatusDescription(int code);
        //
        // 摘要:
        //     获取整个 HTTP 请求正文的长度。
        //
        // 返回结果:
        //     包含整个 HTTP 请求正文的长度的整数。
        public virtual int GetTotalEntityBodyLength();
        //
        // 摘要:
        //     返回非标准的 HTTP 请求标头值。
        //
        // 参数:
        //   name:
        //     标头名称。
        //
        // 返回结果:
        //     标头值。
        public virtual string GetUnknownRequestHeader(string name);
        //
        // 摘要:
        //     获取所有非标准的 HTTP 标头的名称/值对。
        //
        // 返回结果:
        //     标头的名称/值对的数组。
        [CLSCompliant(false)]
        public virtual string[][] GetUnknownRequestHeaders();
        //
        // 摘要:
        //     返回请求的 URI 的虚拟路径。
        //
        // 返回结果:
        //     请求的 URI 的路径。
        public abstract string GetUriPath();
        //
        // 摘要:
        //     当在派生类中被重写时,返回当前连接的上下文 ID。
        //
        // 返回结果:
        //     始终返回 0。
        public virtual long GetUrlContextID();
        //
        // 摘要:
        //     在派生类中被重写时,返回客户端的模拟标记。
        //
        // 返回结果:
        //     表示客户端的模拟标记的值。默认值为 0。
        public virtual IntPtr GetUserToken();
        //
        // 摘要:
        //     获取请求虚拟路径的模拟标记。
        //
        // 返回结果:
        //     请求虚拟路径的标记的非托管内存指针。
        public virtual IntPtr GetVirtualPathToken();
        //
        // 摘要:
        //     返回一个值,该值指示请求是否包含正文数据。
        //
        // 返回结果:
        //     如果请求包含正文数据,则为 true;否则,为 false。
        public bool HasEntityBody();
        //
        // 摘要:
        //     返回一个值,该值指示是否已为当前的请求将 HTTP 响应标头发送到客户端。
        //
        // 返回结果:
        //     如果 HTTP 响应标头已发送到客户端,则为 true;否则,为 false。
        public virtual bool HeadersSent();
        //
        // 摘要:
        //     返回一个值,该值指示客户端连接是否仍处于活动状态。
        //
        // 返回结果:
        //     如果客户端连接仍处于活动状态,则为 true;否则,为 false。
        public virtual bool IsClientConnected();
        //
        // 摘要:
        //     返回一个值,该值指示是否所有请求数据都可用,以及是否不需要对客户端进行进一步读取。
        //
        // 返回结果:
        //     如果所有请求数据都可用,则为 true;否则,为 false。
        public virtual bool IsEntireEntityBodyIsPreloaded();
        //
        // 摘要:
        //     返回一个指示连接是否使用 SSL 的值。
        //
        // 返回结果:
        //     如果连接是 SSL 连接,则为 true;否则为 false。默认值为 false。
        public virtual bool IsSecure();
        //
        // 摘要:
        //     返回与指定虚拟路径相对应的物理路径。
        //
        // 参数:
        //   virtualPath:
        //     虚拟路径。
        //
        // 返回结果:
        //     与 virtualPath 参数中指定的虚拟路径相对应的物理路径。
        public virtual string MapPath(string virtualPath);
        //
        // 摘要:
        //     读取客户端的请求数据(在尚未预加载时)。
        //
        // 参数:
        //   buffer:
        //     将数据读入的字节数组。
        //
        //   size:
        //     最多读取的字节数。
        //
        // 返回结果:
        //     读取的字节数。
        public virtual int ReadEntityBody(byte[] buffer, int size);
        //
        // 摘要:
        //     使用指定的要从中读取数据的缓冲区、字节偏移量和最大字节数从客户端读取请求数据(当未预先加载时)。
        //
        // 参数:
        //   buffer:
        //     将数据读入的字节数组。
        //
        //   offset:
        //     开始读取的位置的字节偏移量。
        //
        //   size:
        //     最多读取的字节数。
        //
        // 返回结果:
        //     读取的字节数。
        public virtual int ReadEntityBody(byte[] buffer, int offset, int size);
        //
        // 摘要:
        //     将 Content-Length HTTP 标头添加到小于或等于 2 GB 的消息正文的响应。
        //
        // 参数:
        //   contentLength:
        //     响应的长度(以字节为单位)。
        public virtual void SendCalculatedContentLength(int contentLength);
        //
        // 摘要:
        //     将 Content-Length HTTP 标头添加到大于 2 GB 的消息正文的响应。
        //
        // 参数:
        //   contentLength:
        //     响应的长度(以字节为单位)。
        public virtual void SendCalculatedContentLength(long contentLength);
        //
        // 摘要:
        //     将标准 HTTP 标头添加到响应。
        //
        // 参数:
        //   index:
        //     标头索引。例如 System.Web.HttpWorkerRequest.HeaderContentLength。
        //
        //   value:
        //     标头的值。
        public abstract void SendKnownResponseHeader(int index, string value);
        //
        // 摘要:
        //     将指定文件的内容添加到响应并指定文件中的起始位置和要发送的字节数。
        //
        // 参数:
        //   handle:
        //     要发送的文件的句柄。
        //
        //   offset:
        //     文件中的起始位置。
        //
        //   length:
        //     要发送的字节数。
        public abstract void SendResponseFromFile(IntPtr handle, long offset, long length);
        //
        // 摘要:
        //     将指定文件的内容添加到响应并指定文件中的起始位置和要发送的字节数。
        //
        // 参数:
        //   filename:
        //     要发送的文件的名称。
        //
        //   offset:
        //     文件中的起始位置。
        //
        //   length:
        //     要发送的字节数。
        public abstract void SendResponseFromFile(string filename, long offset, long length);
        //
        // 摘要:
        //     将字节数组中指定数目的字节添加到响应。
        //
        // 参数:
        //   data:
        //     要发送的字节数组。
        //
        //   length:
        //     要发送的字节数(从第一个字节开始)。
        public abstract void SendResponseFromMemory(byte[] data, int length);
        //
        // 摘要:
        //     将内存块中指定数目的字节添加到响应。
        //
        // 参数:
        //   data:
        //     指向内存块的非托管指针。
        //
        //   length:
        //     要发送的字节数。
        public virtual void SendResponseFromMemory(IntPtr data, int length);
        //
        // 摘要:
        //     指定响应的 HTTP 状态代码和状态说明,例如 SendStatus(200, "Ok")。
        //
        // 参数:
        //   statusCode:
        //     要发送的状态代码
        //
        //   statusDescription:
        //     要发送的状态说明。
        public abstract void SendStatus(int statusCode, string statusDescription);
        //
        // 摘要:
        //     将非标准 HTTP 标头添加到响应。
        //
        // 参数:
        //   name:
        //     要发送的标头的名称。
        //
        //   value:
        //     标头的值。
        public abstract void SendUnknownResponseHeader(string name, string value);
        //
        // 摘要:
        //     在发送所有响应数据后注册可选通知。
        //
        // 参数:
        //   callback:
        //     在发送所有数据(带外)后调用的通知回调。
        //
        //   extraData:
        //     回调的附加参数。
        public virtual void SetEndOfSendNotification(HttpWorkerRequest.EndOfSendNotification callback, object extraData);

        // 摘要:
        //     表示用于在完成发送响应后通知调用方的方法。
        //
        // 参数:
        //   wr:
        //     当前的 System.Web.HttpWorkerRequest。
        //
        //   extraData:
        //     处理请求所需的任何其他数据。
        public delegate void EndOfSendNotification(HttpWorkerRequest wr, object extraData);
    }

 

时间: 2024-07-30 10:34:55

艾伟_转载:HttpRuntime的认识与加深理解的相关文章

艾伟_转载:老赵谈IL(3):IL可以看到的东西,其实大都也可以用C#来发现

在上一篇文章中,我们通过一些示例谈论了IL与CLR中的一些特性.IL与C#等高级语言的作用类似,主要用于表示程序的逻辑.由于它同样了解太多CLR中的高级特性,因此它在大部分情况下依旧无法展现出比那些高级语言更多的CLR细节.因此,如果您想要通过学习IL来了解CLR,那么这个过程很可能会"事倍功半".因此,从这个角度来说,老赵并不倾向于学习IL.不过严格说来,即使IL无法看出CLR的细节,也不足以说明"IL无用"--这里说"无用"自然有些夸张.但是

艾伟_转载:基于.NET平台的Windows编程实战(六)—— 题目管理功能的实现

本系列文章导航 基于.NET平台的Windows编程实战(一)--前言 基于.NET平台的Windows编程实战(二)-- 需求分析与数据库设计 基于.NET平台的Windows编程实战(四)-- 数据库操作类的编写 基于.NET平台的Windows编程实战(五)-- 问卷管理功能的实现 基于.NET平台的Windows编程实战(六)-- 题目管理功能的实现 申明:本系列课程是专为新手们写来入门练习用的,目的是想通过一个完整的问卷调查管理系统的案例开发来让新手们了解.加深或是熟悉软件项目的开发流

艾伟_转载:[原创]再谈IIS与ASP.NET管道

在2007年9月份,我曾经写了三篇详细介绍IIS架构和ASP.NET运行时管道的文章,深入介绍了IIS 5.x与IIS 6.0HTTP请求的监听与分发机制,以及ASP.NET运行时管道对HTTP请求的处理流程: [原创]ASP.NET Process Model之一:IIS 和 ASP.NET ISAPI[原创]ASP.NET Process Model之二:ASP.NET Http Runtime Pipeline - Part I[原创]ASP.NET Process Model之二:ASP

艾伟_转载:数组排序方法的性能比较(上):注意事项及试验

昨天有朋友写了一篇文章,其中比较了List的Sort方法与LINQ中排序方法的性能,而最终得到的结果是"LINQ排序方法性能高于List.Sort方法".这个结果不禁让我很疑惑.因为List.Sort方法是改变容器内部元素的顺序,而LINQ排序后得到的是一个新的序列.假如两个排序方法的算法完全一致,LINQ排序也比对方多出元素复制的开销,为什么性能反而会高?如果LINQ排序的算法/实现更为优秀,那为什么.NET Fx不将List.Sort也一并优化一下呢?于是今天我也对这个问题进行了简

艾伟_转载:一个MVC分页Helper

本人写的一个分页Helper,支持普通分页(也就是,首页.上一页.下一页.末页等),综合分页(普通分页和数字分页的综合).下面是分页效果: 分页代码: PagerHelper.cs 代码   1 using System;  2  using System.Collections.Generic;  3 using System.Collections.Specialized;  4 using System.Linq;  5 using System.Web;  6 using System.

艾伟_转载:WCF版的PetShop之三:实现分布式的Membership和上下文传递

本系列文章导航 WCF版的PetShop之一:PetShop简介 WCF版的PetShop之二:模块中的层次划分 WCF版的PetShop之三:实现分布式的Membership和上下文传递 通过上一篇了解了模块内基本的层次划分之后,接下来我们来聊聊PetShop中一些基本基础功能的实现,以及一些设计.架构上的应用如何同WCF进行集成.本篇讨论两个问题:实现分布式的Membership和客户端到服务端上下文(Context)的传递. 一. 如何实现用户验证 对登录用户的验证是大部分应用所必需的,对

艾伟_转载:一次挂死(hang)的处理过程及经验

 前言:        CPU占用率低,内存还有许多空余,但网站无法响应,这就是网站挂死,通常也叫做hang.这种情况对于我这样既是CEO,又是CTO,还兼职扫地洗碗的个人站长来说根本就是家常便饭.以下是一次处理hang的经验及总结,前后用了一个月,不仅涉及程序排查,数据库优化,还有硬件升级的苦恼.其中辛酸苦辣只有经历过的站长才能体会,希望此文能对各位有所帮助!        首先介绍一下网站基本情况,是一个在线小说阅读网站,每天有一定页面访问量,在优化开始前由两台服务器运行,均为Dell Po

艾伟_转载:从ASP.NET的PHP执行速度比较谈起

上星期我在InfoQ发表了一篇新闻,对Joe Stagner在博客上发表的三篇关于ASP.NET与PHP性能对比的文章进行了总结.写新闻其实挺不爽的,因为不能夹杂个人的看法,只能平铺直叙陈述事实.当然,如果像某些新闻那样"换一种说法"是可以骗过一些"不明真相的群众",但是这就有违道德了.因此,在客观陈述完新闻内容之后,我只能选择把自己的感想.评论等内容放在自己的博客上. Joe Stagner的背景挺特殊,它是PHP的老用户,在ASP.NET出现之前就是PHP的重量

艾伟_转载:在Mono中创建ASP.NET程序

一只可爱的猴子: 一次偶然的机会碰到这只猴子,并在工作中也用到它了.现将自己的使用经验分享与此(以OpenSUSE为例介绍). 对于不熟悉Mono的朋友来说,Mono就是.Net在Linux和其它操作系统上的实现(Unix.Mac.iphone.Windows...).Mono的官方网站是:http://www.mono-project.com 严格来讲,Mono是一个开源的.跨平台的C#语言和其CLR的实现,并与微软的.NET二进制兼容.很绕口吧,这是Mono官方网站写的:An open so