欢迎来到天天文库
浏览记录
ID:30775854
大小:87.00 KB
页数:8页
时间:2019-01-03
《aspnet源码解析(一)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Asp.Net源码解析(一)上面两篇文章说了http协议和IIS处理,这次说下当IIS把请求交给Asp.net后的过程。AppManagerAppDomainFactory当IIS把请求交给asp.net时候,如果AppDomain还不存在则创建APPDomain,将AppDomain指派给与请求对应的应用程序,这通过AppManagerAppDomainFactory类屮的Create丿了法实现,代码如下:publicObjectCreate(Stringappld,StringappPath){try{讦(appPath[O]=={Syste
2、m.10.Fileinfofile=newSystem.10.Filelnfo(appPath);appPath=file.FullName;}if(IStringUtil.StringEndsWithfappPath,'\')){appPath=appPath+";ISAPIApplicationHostappHost=newISAPIApplicationHost(appld,appPath,false);〃创建环境,包括编译环境ISAPIRuntimeisapiRuntime=(ISAPIRuntime)_appManager.Cr
3、eateObjectlnternal(appld,typeof(ISAPIRuntime),appHost,false,null);isapiRuntime.StartProcessing();returnnewObjectHandle(isapiRuntime);}catch(Exceptione){•••}}创建完成后,非托管代码开始调用ISAPIRuntime中ProcessRequest方法(通过COM调用)ISAPIRuntime-asp.net入口首先看下ISAPIRuntime中的ProcessRequest方法签名publicin
4、tProcessRequest(lntPtrecb,intiWRType);ProcessRequest有两个参数,一个是请求报文的ecb句柄,一个请求的类型,在运行的过程中,ecb首先被再次封装成托管资源的请求报文wro把封装好的代码传递给HttpRuntime类中的ProcessRequestNoDemand.核心代码如下:booluseOOP=(iWRType==WORKER_REQUEST_TYPE_OOP);wr=ISAPIWorkerRequest.CreateWorkerRequest(ecb,useOOP);wr.lnitiali
5、ze();//checkifapppathmatches(needtorestartappdomain?)StringwrPath=wr.GetAppPathTranslated();StringadPath=HttpRuntime.AppDomainAppPathlnternal;讦(adPath==null11StringUtil.EqualsIgnoreCasefwrPath,adPath)){HttpRuntime.ProcessRequestNoDemand(wr);return0;}else{//needtorestartappdom
6、ainHttpRuntime.ShutdownAppDomain(ApplicationShutdownReason.PhysicalApplicationPathChanged,SR.GetString(SR.Hosting_Phys_Path_Changed/adPath,wrPath));return1;}HttpRuntimeHttpRuntime收到传递过来的HttpWorkerRequest类的实例对象wr,通过调用当前类屮的ProcessRequestNow方法,把参数传递给ProcessRequestlnternal(Proces
7、sRequestNow的调用ProcessRequestlnternal)。internalstaticvoidProcessRequestNoDemand(HttpWorkerRequestwr){RequestQueuerq=_theRuntime._requestQueue;wr.UpdatelnitialCounters();if(rq!=null)//couldbenullbeforefirstrequestwr=rq.GetRequestToExecute(wr);if(wr!=null){CalculateWaitTimeAndU
8、pdatePerfCounter(wr);wr.ResetStartTime();ProcessRequestNow(wr);}}int
此文档下载收益归作者所有