asp.net运行机制



ISAPIRuntime的ProcessRequest方法

public sealed class ISAPIRuntime : MarshalByRefObject, IISAPIRuntime, IISAPIRuntime2, IRegisteredObject
{
...
public int ProcessRequest(IntPtr ecb, int iWRType)
{
...
ISAPIWorkerRequest wr = null;
...
创建了ISAPIWorkerRequest对象,这个对象中包含了请求报文,但此时的请求报文程序员是无法使用的,需要进一步封装
wr = ISAPIWorkerRequest.CreateWorkerRequest(ecb, useOOP);
...
HttpRuntime.ProcessRequestNoDemand(wr);

}
...
}


public sealed class HttpRuntime
{
...
private static HttpRuntime _theRuntime;
...
private void ProcessRequestNoDemand(HttpWorkerRequest wr)
{
internal static void ProcessRequestNoDemand(HttpWorkerRequest wr)
{
...
//这是一个队列对象,也就是说请求队列,按顺序执行
RequestQueue queue = _theRuntime._requestQueue;
...
ProcessRequestNow(wr);
}
}
internal static void ProcessRequestNow(HttpWorkerRequest wr)
{
_theRuntime.ProcessRequestInternal(wr);
}
private void ProcessRequestInternal(HttpWorkerRequest wr)
{
//ASP.Net中非常重要的context(请求上下文)对象在此时被创建出来
//但是此时wr对象里只包含有请求报文,所以Response对象是没有数据的。
...
HttpContext context;
        try
        {
            context = new HttpContext(wr, false);
        }
...
//在这初始化了Response的一个文本写出器,也就是缓冲区,服务器返回给浏览器的数据被暂时缓存在这里。
context.Response.InitResponseWriter();
//又一个伟大的对象诞生了,即HttpApplication对象被创建出来了。
        IHttpHandler applicationInstance = HttpApplicationFactory.GetApplicationInstance(context);
...
if (applicationInstance is IHttpAsyncHandler)
{
IHttpAsyncHandler handler2 = (IHttpAsyncHandler) applicationInstance;
context.AsyncAppHandler = handler2;
//调用application对象的BeginProcessRequest方法,即开始执行19个管道事件了
handler2.BeginProcessRequest(context, this._handlerCompletionCallback, context);
}
...
}
}


public sealed class HttpContext : IServiceProvider, IPrincipalContainer
{
//在HttpContext类中包含了两个重要的对象,即:
private HttpRequest _request;
    private HttpResponse _response;
//HttpContext的构造方法
internal HttpContext(HttpWorkerRequest wr, bool initResponseWriter)
{
this._wr = wr;
//调用HttpContext类中的Init方法来初始化HttpRequest和HttpResponse对象。
this.Init(new HttpRequest(wr, this), new HttpResponse(wr, this));
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值