private void ChooseAndInitConfigMapPath(bool useConfigMapPath, IConfigMapPath configMapPath, ConfigurationFileMap fileMap) { if (useConfigMapPath) { this._configMapPath = configMapPath; } else if (fileMap != null) { this._configMapPath = new UserMapPath(fileMap); } else if (HostingEnvironment.IsHosted) { this._configMapPath = HostingPreferredMapPath.GetInstance(); } else { this._configMapPath = IISMapPath.GetInstance(); } this._configMapPath2 = this._configMapPath as IConfigMapPath2; }
internal void Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) { _hostingParameters = hostingParameters; HostingEnvironmentFlags hostingFlags = HostingEnvironmentFlags.Default; if (_hostingParameters != null) { hostingFlags = _hostingParameters.HostingFlags; if (_hostingParameters.IISExpressVersion != null) { ServerConfig.IISExpressVersion = _hostingParameters.IISExpressVersion; } } // Keep track of the app manager, unless HideFromAppManager flag was passed if ((hostingFlags & HostingEnvironmentFlags.HideFromAppManager) == 0) _appManager = appManager; if ((hostingFlags & HostingEnvironmentFlags.ClientBuildManager) != 0) { BuildManagerHost.InClientBuildManager = true; } if ((hostingFlags & HostingEnvironmentFlags.SupportsMultiTargeting) != 0) { BuildManagerHost.SupportsMultiTargeting = true; } // // init config system using private config if applicable // if (appHost is ISAPIApplicationHost && !ServerConfig.UseMetabase) { string rootWebConfigPath = ((ISAPIApplicationHost)appHost).ResolveRootWebConfigPath(); if (!String.IsNullOrEmpty(rootWebConfigPath)) { Debug.Assert(File.Exists(rootWebConfigPath), "File.Exists(rootWebConfigPath)"); HttpConfigurationSystem.RootWebConfigurationFilePath = rootWebConfigPath; } // we need to explicit create a COM proxy in this app domain // so we don't go back to the default domain or have lifetime issues // remember support functions IProcessHostSupportFunctions proxyFunctions = ((ISAPIApplicationHost)appHost).SupportFunctions; if (null != proxyFunctions) { _functions = Misc.CreateLocalSupportFunctions(proxyFunctions); } } _appId = HttpRuntime.AppDomainAppId; _appVirtualPath = HttpRuntime.AppDomainAppVirtualPathObject; _appPhysicalPath = HttpRuntime.AppDomainAppPathInternal; _appHost = appHost; _configMapPath = configMapPathFactory.Create(_appVirtualPath.VirtualPathString, _appPhysicalPath); HttpConfigurationSystem.EnsureInit(_configMapPath, true, false); // attempt to cache and use IConfigMapPath2 provider // which supports VirtualPath's to save on conversions _configMapPath2 = _configMapPath as IConfigMapPath2; _initiateShutdownWorkItemCallback = new WaitCallback(this.InitiateShutdownWorkItemCallback); // notify app manager if (_appManager != null) { _appManager.HostingEnvironmentActivated(CacheMemorySizePressure.EffectiveProcessMemoryLimit); } // make sure there is always app host if (_appHost == null) { _appHost = new SimpleApplicationHost(_appVirtualPath, _appPhysicalPath); } else { _externalAppHost = true; } // remember the token to access config _configToken = _appHost.GetConfigToken(); // Start with a MapPath based virtual path provider _mapPathBasedVirtualPathProvider = new MapPathBasedVirtualPathProvider(); _virtualPathProvider = _mapPathBasedVirtualPathProvider; // initiaze HTTP-independent features HttpRuntime.InitializeHostingFeatures(hostingFlags, policyLevel, appDomainCreationException); // VSWhidbey 393259. Do not monitor idle timeout for CBM since Venus // will always restart a new appdomain if old one is shutdown. if (!BuildManagerHost.InClientBuildManager) { // start monitoring for idle inside app domain StartMonitoringForIdleTimeout(); } // notify app manager if the app domain limit is violated EnforceAppDomainLimit(); // get application identity (for explicit impersonation mode) GetApplicationIdentity(); // call AppInitialize, unless the flag says not to do it (e.g. CBM scenario). // Also, don't call it if HostingInit failed (VSWhidbey 210495) if(!HttpRuntime.HostingInitFailed) { try { BuildManager.ExecutePreAppStart(); if ((hostingFlags & HostingEnvironmentFlags.DontCallAppInitialize) == 0) { BuildManager.CallAppInitializeMethod(); } } catch (Exception e) { // could throw compilation errors in 'code' - report them with first http request HttpRuntime.InitializationException = e; if ((hostingFlags & HostingEnvironmentFlags.ThrowHostingInitErrors) != 0) { throw; } } } }
internal void Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) { this._hostingParameters = hostingParameters; HostingEnvironmentFlags hostingFlags = HostingEnvironmentFlags.Default; if (this._hostingParameters != null) { hostingFlags = this._hostingParameters.HostingFlags; if (this._hostingParameters.IISExpressVersion != null) { ServerConfig.IISExpressVersion = this._hostingParameters.IISExpressVersion; } } if ((hostingFlags & HostingEnvironmentFlags.HideFromAppManager) == HostingEnvironmentFlags.Default) { this._appManager = appManager; } if ((hostingFlags & HostingEnvironmentFlags.ClientBuildManager) != HostingEnvironmentFlags.Default) { BuildManagerHost.InClientBuildManager = true; } if ((hostingFlags & HostingEnvironmentFlags.SupportsMultiTargeting) != HostingEnvironmentFlags.Default) { BuildManagerHost.SupportsMultiTargeting = true; } if ((appHost is ISAPIApplicationHost) && !ServerConfig.UseMetabase) { string str = ((ISAPIApplicationHost) appHost).ResolveRootWebConfigPath(); if (!string.IsNullOrEmpty(str)) { HttpConfigurationSystem.RootWebConfigurationFilePath = str; } IProcessHostSupportFunctions supportFunctions = ((ISAPIApplicationHost) appHost).SupportFunctions; if (supportFunctions != null) { _functions = Misc.CreateLocalSupportFunctions(supportFunctions); } } this._appId = HttpRuntime.AppDomainAppIdInternal; this._appVirtualPath = HttpRuntime.AppDomainAppVirtualPathObject; this._appPhysicalPath = HttpRuntime.AppDomainAppPathInternal; this._appHost = appHost; this._configMapPath = configMapPathFactory.Create(this._appVirtualPath.VirtualPathString, this._appPhysicalPath); HttpConfigurationSystem.EnsureInit(this._configMapPath, true, false); this._configMapPath2 = this._configMapPath as IConfigMapPath2; this._initiateShutdownWorkItemCallback = new WaitCallback(this.InitiateShutdownWorkItemCallback); if (this._appManager != null) { this._appManager.HostingEnvironmentActivated(CacheMemorySizePressure.EffectiveProcessMemoryLimit); } if (this._appHost == null) { this._appHost = new SimpleApplicationHost(this._appVirtualPath, this._appPhysicalPath); } else { this._externalAppHost = true; } this._configToken = this._appHost.GetConfigToken(); this._mapPathBasedVirtualPathProvider = new MapPathBasedVirtualPathProvider(); this._virtualPathProvider = this._mapPathBasedVirtualPathProvider; HttpRuntime.InitializeHostingFeatures(hostingFlags, policyLevel, appDomainCreationException); if (!BuildManagerHost.InClientBuildManager) { this.StartMonitoringForIdleTimeout(); } this.EnforceAppDomainLimit(); this.GetApplicationIdentity(); if (!HttpRuntime.HostingInitFailed) { try { BuildManager.CallPreStartInitMethods(); if ((hostingFlags & HostingEnvironmentFlags.DontCallAppInitialize) == HostingEnvironmentFlags.Default) { BuildManager.CallAppInitializeMethod(); } } catch (Exception exception) { HttpRuntime.InitializationException = exception; if ((hostingFlags & HostingEnvironmentFlags.ThrowHostingInitErrors) != HostingEnvironmentFlags.Default) { throw; } } } }