上面两篇文章说了http协议和IIS处理,这次说下当IIS把请求交给Asp.net后的过程。

AppManagerAppDomainFactory

  1. 当IIS把请求交给asp.net时候,如果AppDomain还不存在则创建APPDomain,将AppDomain指派给与请求对应的应用程序,这通过AppManagerAppDomainFactory类中的Create方法实现,代码如下:

        public Object Create(String appId, String appPath) {       try {           if (appPath[0] == '.') {
                   System.IO.FileInfo file = new System.IO.FileInfo(appPath);
                   appPath = file.FullName;
               }           if (!StringUtil.StringEndsWith(appPath, '\\')) {
                   appPath = appPath + "\\";
               }
    
               ...
    
               ISAPIApplicationHost appHost = new ISAPIApplicationHost(appId, appPath,false);           //创建环境,包括编译环境
               ISAPIRuntime isapiRuntime = (ISAPIRuntime)_appManager.CreateObjectInternal(appId, typeof(ISAPIRuntime), appHost,  false, null);
               isapiRuntime.StartProcessing();           return new ObjectHandle(isapiRuntime);
    
           }       catch (Exception e) {
                &n