public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams) { bool useConfigMapPath = (bool)hostInitParams[0]; IConfigMapPath configMapPath = (IConfigMapPath)hostInitParams[1]; ConfigurationFileMap fileMap = (ConfigurationFileMap)hostInitParams[2]; string path = (string)hostInitParams[3]; string str2 = (string)hostInitParams[4]; string str3 = (string)hostInitParams[5]; if (hostInitParams.Length > 6) { string moniker = hostInitParams[6] as string; this._machineConfigFile = GetMachineConfigPathFromTargetFrameworkMoniker(moniker); if (!string.IsNullOrEmpty(this._machineConfigFile)) { this._rootWebConfigFile = Path.Combine(Path.GetDirectoryName(this._machineConfigFile), "web.config"); } } base.Host.Init(configRoot, hostInitParams); this.ChooseAndInitConfigMapPath(useConfigMapPath, configMapPath, fileMap); path = System.Web.Util.UrlPath.RemoveSlashFromPathIfNeeded(path); this._appPath = VirtualPath.CreateAbsoluteAllowNull(path); this._appSiteName = str2; this._appSiteID = str3; if (!string.IsNullOrEmpty(this._appSiteID) && (this._appPath != null)) { this._appConfigPath = GetConfigPathFromSiteIDAndVPath(this._appSiteID, this._appPath); } }
/// <summary> /// Hook the internal .NET MapPath function in order to change its behaviour to handle virtual paths /// </summary> /// <exception cref="System.ArgumentNullException"> /// _theHostingEnvironment is null /// or /// _configMapPath is null /// </exception> private void HookMapPath() { FieldInfo fieldInstance = typeof(HostingEnvironment).GetField("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static); FieldInfo fieldConfigMapPath = typeof(HostingEnvironment).GetField("_configMapPath", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo fieldConfigMapPath2 = typeof(HostingEnvironment).GetField("_configMapPath2", BindingFlags.NonPublic | BindingFlags.Instance); // Obtain the internal hosting environment instance (_theHostingEnvironment) HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)fieldInstance.GetValue(null); if (hostingEnvironmentInstance == null) { throw new ArgumentNullException("_theHostingEnvironment is null"); } // Obtain the instantiated IConfigMapPath interface object mOriginal = (IConfigMapPath)fieldConfigMapPath.GetValue(hostingEnvironmentInstance); if (mOriginal == null) { throw new ArgumentNullException("_configMapPath is null"); } // Replace the HostingEnvironment IConfigMapPath object with our own fieldConfigMapPath.SetValue(hostingEnvironmentInstance, this); // Disable any IIS specific IConfigMapPath2 object fieldConfigMapPath2.SetValue(hostingEnvironmentInstance, null); }
// // Set this configuration system to the default for requests ConfigurationManager.GetSection // static internal void EnsureInit(IConfigMapPath configMapPath, bool listenToFileChanges, bool initComplete) { if (!s_inited) { lock (s_initLock) { if (!s_inited) { s_initComplete = initComplete; // Use the IIS map path if one is not explicitly provided if (configMapPath == null) { configMapPath = IISMapPath.GetInstance(); } s_configMapPath = configMapPath; Type typeConfigSystem = Type.GetType(ConfigSystemTypeString, true); s_configSystem = (IConfigSystem) Activator.CreateInstance(typeConfigSystem, true); s_configSystem.Init( typeof(WebConfigurationHost), // The config host we'll create and use // The remaining parameters are passed to the config host: true, // Use the supplied configMapPath s_configMapPath, // the configMapPath to use null, // ConfigurationFileMap HostingEnvironment.ApplicationVirtualPath, // app path HostingEnvironment.SiteNameNoDemand, // app site name HostingEnvironment.SiteID); // app site ID s_configRoot = s_configSystem.Root; s_configHost = (WebConfigurationHost) s_configSystem.Host; // Register for config changed notifications HttpConfigurationSystem configSystem = new HttpConfigurationSystem(); if (listenToFileChanges) { s_configRoot.ConfigChanged += new InternalConfigEventHandler(configSystem.OnConfigurationChanged); } // Set the configSystem into the ConfigurationManager class. // Please note that factory.SetConfigurationSystem will end up calling // ConfigurationManager.SetConfigurationSystem, which is an internal static method // in System.Configuration.dll. If we want to call that here, we have to use // reflection and that's what we want to avoid. Type typeFactory = Type.GetType(InternalConfigSettingsFactoryTypeString, true); s_configSettingsFactory = (IInternalConfigSettingsFactory) Activator.CreateInstance(typeFactory, true); s_configSettingsFactory.SetConfigurationSystem(configSystem, initComplete); // The system has been successfully set, so mark that we should use it. s_httpConfigSystem = configSystem; // Mark as having completed initialization after s_httpConfigSystem has been set. // s_inited is coordinated with s_httpConfigSystem in UseHttpConfigurationSystem. s_inited = true; } } } Debug.Assert(s_httpConfigSystem != null, "s_httpConfigSystem != null - The appdomain is using the client configuration system."); }
internal static IConfigMapPath GetInstance() { IConfigMapPath instance = IISMapPath.GetInstance(); IConfigMapPath configMapPath = HostingEnvironment.ConfigMapPath; if ((configMapPath != null) && !(instance.GetType() == configMapPath.GetType())) { return(new HostingPreferredMapPath(instance, configMapPath)); } return(instance); }
internal static IConfigMapPath GetInstance() { IConfigMapPath iisConfigMapPath = IISMapPath.GetInstance(); IConfigMapPath hostingConfigMapPath = HostingEnvironment.ConfigMapPath; // Only delegate if the types implementing IConfigMapPath are different. if (hostingConfigMapPath == null || iisConfigMapPath.GetType() == hostingConfigMapPath.GetType()) { return(iisConfigMapPath); } return(new HostingPreferredMapPath(iisConfigMapPath, hostingConfigMapPath)); }
public string GetFilePaths(int webLevelAsInt, string path, string site, string locationSubPath) { string str; string str2; VirtualPath path3; string str3; string str4; string str5; VirtualPath path4; WebLevel webLevel = (WebLevel)webLevelAsInt; IConfigMapPath instance = IISMapPath.GetInstance(); WebConfigurationHost.GetConfigPaths(instance, webLevel, VirtualPath.CreateNonRelativeAllowNull(path), site, locationSubPath, out path3, out str, out str2, out str3, out str4); ArrayList list = new ArrayList(); list.Add(VirtualPath.GetVirtualPathString(path3)); list.Add(str); list.Add(str2); list.Add(str3); list.Add(str4); WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(str3, out str5, out path4); list.Add("machine"); list.Add(HttpConfigurationSystem.MachineConfigurationFilePath); if (webLevel != WebLevel.Machine) { list.Add("machine/webroot"); list.Add(HttpConfigurationSystem.RootWebConfigurationFilePath); for (VirtualPath path5 = path4; path5 != null; path5 = path5.Parent) { string configPathFromSiteIDAndVPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(str2, path5); string str7 = Path.Combine(instance.MapPath(str2, path5.VirtualPathString), "web.config"); list.Add(configPathFromSiteIDAndVPath); list.Add(str7); } } StringBuilder builder = new StringBuilder(); for (int i = 0; i < list.Count; i++) { if (i > 0) { builder.Append('<'); } string str8 = (string)list[i]; builder.Append(str8); } return(builder.ToString()); }
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; }
public override void Init(IInternalConfigRoot configRoot, params object[] hostInitParams) { bool useConfigMapPath = (bool)hostInitParams[0]; IConfigMapPath configMapPath = (IConfigMapPath)hostInitParams[1]; ConfigurationFileMap fileMap = (ConfigurationFileMap)hostInitParams[2]; string appPath = (string)hostInitParams[3]; string appSiteName = (string)hostInitParams[4]; string appSiteID = (string)hostInitParams[5]; if (hostInitParams.Length > 6) { // If VS sent a 7th param, it is the .Net Framwework Target version moniker string fxMoniker = hostInitParams[6] as string; _machineConfigFile = GetMachineConfigPathFromTargetFrameworkMoniker(fxMoniker); if (!string.IsNullOrEmpty(_machineConfigFile)) { _rootWebConfigFile = Path.Combine(Path.GetDirectoryName(_machineConfigFile), "web.config"); } } Debug.Assert(configMapPath == null || useConfigMapPath, "non-null configMapPath without useConfigMapPath == true"); Host.Init(configRoot, hostInitParams); ChooseAndInitConfigMapPath(useConfigMapPath, configMapPath, fileMap); appPath = UrlPath.RemoveSlashFromPathIfNeeded(appPath); _appPath = VirtualPath.CreateAbsoluteAllowNull(appPath); _appSiteName = appSiteName; _appSiteID = appSiteID; if (!String.IsNullOrEmpty(_appSiteID) && _appPath != null) { _appConfigPath = GetConfigPathFromSiteIDAndVPath(_appSiteID, _appPath); } #if DBG _inited = true; #endif }
internal static void EnsureInit(IConfigMapPath configMapPath, bool listenToFileChanges, bool initComplete) { if (!s_inited) { lock (s_initLock) { if (!s_inited) { s_initComplete = initComplete; if (configMapPath == null) { configMapPath = IISMapPath.GetInstance(); } s_configMapPath = configMapPath; s_configSystem = (IConfigSystem) Activator.CreateInstance(Type.GetType("System.Configuration.Internal.ConfigSystem, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true), true); object[] hostInitParams = new object[6]; hostInitParams[0] = true; hostInitParams[1] = s_configMapPath; hostInitParams[3] = HostingEnvironment.ApplicationVirtualPath; hostInitParams[4] = HostingEnvironment.SiteNameNoDemand; hostInitParams[5] = HostingEnvironment.SiteID; s_configSystem.Init(typeof(WebConfigurationHost), hostInitParams); s_configRoot = s_configSystem.Root; s_configHost = (WebConfigurationHost) s_configSystem.Host; HttpConfigurationSystem internalConfigSystem = new HttpConfigurationSystem(); if (listenToFileChanges) { s_configRoot.ConfigChanged += new InternalConfigEventHandler(internalConfigSystem.OnConfigurationChanged); } s_configSettingsFactory = (IInternalConfigSettingsFactory) Activator.CreateInstance(Type.GetType("System.Configuration.Internal.InternalConfigSettingsFactory, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true), true); s_configSettingsFactory.SetConfigurationSystem(internalConfigSystem, initComplete); s_httpConfigSystem = internalConfigSystem; s_inited = true; } } } }
internal static void EnsureInit(IConfigMapPath configMapPath, bool listenToFileChanges, bool initComplete) { if (!s_inited) { lock (s_initLock) { if (!s_inited) { s_initComplete = initComplete; if (configMapPath == null) { configMapPath = IISMapPath.GetInstance(); } s_configMapPath = configMapPath; s_configSystem = (IConfigSystem)Activator.CreateInstance(Type.GetType("System.Configuration.Internal.ConfigSystem, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true), true); object[] hostInitParams = new object[6]; hostInitParams[0] = true; hostInitParams[1] = s_configMapPath; hostInitParams[3] = HostingEnvironment.ApplicationVirtualPath; hostInitParams[4] = HostingEnvironment.SiteNameNoDemand; hostInitParams[5] = HostingEnvironment.SiteID; s_configSystem.Init(typeof(WebConfigurationHost), hostInitParams); s_configRoot = s_configSystem.Root; s_configHost = (WebConfigurationHost)s_configSystem.Host; HttpConfigurationSystem internalConfigSystem = new HttpConfigurationSystem(); if (listenToFileChanges) { s_configRoot.ConfigChanged += new InternalConfigEventHandler(internalConfigSystem.OnConfigurationChanged); } s_configSettingsFactory = (IInternalConfigSettingsFactory)Activator.CreateInstance(Type.GetType("System.Configuration.Internal.InternalConfigSettingsFactory, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true), true); s_configSettingsFactory.SetConfigurationSystem(internalConfigSystem, initComplete); s_httpConfigSystem = internalConfigSystem; s_inited = true; } } } }
// Not used in runtime because in runtime we have all the siteid, appPath, etc. already. static internal void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath, out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath) { appPath = null; appSiteName = null; appSiteID = null; if (webLevel == WebLevel.Machine || virtualPath == null) { // Site is meaningless at machine and root web.config level // However, we allow a site parameter if the caller is opening // a location tag. See VSWhidbey 548361. if (!String.IsNullOrEmpty(site) && String.IsNullOrEmpty(locationSubPath)) { throw ExceptionUtil.ParameterInvalid("site"); } if (webLevel == WebLevel.Machine) { configPath = MachineConfigPath; } else { configPath = RootWebConfigPath; } } else { // Get the site name and ID if (!String.IsNullOrEmpty(site)) { configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID); if (String.IsNullOrEmpty(appSiteID)) { throw new InvalidOperationException(SR.GetString(SR.Config_failed_to_resolve_site_id, site)); } } else { // If site not supplied, try hosting environment first if (HostingEnvironment.IsHosted) { appSiteName = HostingEnvironment.SiteNameNoDemand; appSiteID = HostingEnvironment.SiteID; } // Rely on defaults if not provided in hosting environment if (String.IsNullOrEmpty(appSiteID)) { configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID); } Debug.Assert(!String.IsNullOrEmpty(appSiteID), "No appSiteID found when site argument is null"); } configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath); } // get locationConfigPath locationConfigPath = null; string locationSite = null; VirtualPath locationVPath = null; if (locationSubPath != null) { locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath); GetSiteIDAndVPathFromConfigPath(locationConfigPath, out locationSite, out locationVPath); // If we're at machine or root web.config level and a location path is given, // handle the site part of the location path. if (String.IsNullOrEmpty(appSiteID) && !String.IsNullOrEmpty(locationSite)) { configMapPath.ResolveSiteArgument(locationSite, out appSiteName, out appSiteID); if (!String.IsNullOrEmpty(appSiteID)) { // Recompose the location config path based on new appSiteID locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, locationVPath); } else { // If there is no path, then allow the location to be edited, // as we don't need to map elements of the path. if (locationVPath == null || locationVPath.VirtualPathString == "/") { appSiteName = locationSite; appSiteID = locationSite; } // Otherwise, the site argument is ambiguous. else { // appSiteName = null; appSiteID = null; } } } } // get appPath string appPathString = null; if (locationVPath != null) { appPathString = configMapPath.GetAppPathForPath(appSiteID, locationVPath.VirtualPathString); } else if (virtualPath != null) { appPathString = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString); } if (appPathString != null) { appPath = VirtualPath.Create(appPathString); } }
/// <summary> /// Hook the internal .NET MapPath function in order to change its behaviour to handle virtual paths /// </summary> /// <exception cref="System.ArgumentNullException"> /// _theHostingEnvironment is null /// or /// _configMapPath is null /// </exception> private void HookMapPath() { FieldInfo fieldInstance = typeof(HostingEnvironment).GetField("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static); FieldInfo fieldConfigMapPath = typeof(HostingEnvironment).GetField("_configMapPath", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo fieldConfigMapPath2 = typeof(HostingEnvironment).GetField("_configMapPath2", BindingFlags.NonPublic | BindingFlags.Instance); // Obtain the internal hosting environment instance (_theHostingEnvironment) HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)fieldInstance.GetValue(null); if (hostingEnvironmentInstance == null) throw new ArgumentNullException("_theHostingEnvironment is null"); // Obtain the instantiated IConfigMapPath interface object mOriginal = (IConfigMapPath)fieldConfigMapPath.GetValue(hostingEnvironmentInstance); if (mOriginal == null) throw new ArgumentNullException("_configMapPath is null"); // Replace the HostingEnvironment IConfigMapPath object with our own fieldConfigMapPath.SetValue(hostingEnvironmentInstance, this); // Disable any IIS specific IConfigMapPath2 object fieldConfigMapPath2.SetValue(hostingEnvironmentInstance, null); }
public string GetFilePaths(int webLevelAsInt, string path, string site, string locationSubPath) { WebLevel webLevel = (WebLevel)webLevelAsInt; IConfigMapPath configMapPath = IISMapPath.GetInstance(); // Get the configuration paths and application information string appSiteName, appSiteID; VirtualPath appPath; string configPath, locationConfigPath; WebConfigurationHost.GetConfigPaths(configMapPath, webLevel, VirtualPath.CreateNonRelativeAllowNull(path), site, locationSubPath, out appPath, out appSiteName, out appSiteID, out configPath, out locationConfigPath); // // Format of filePaths: // appPath < appSiteName < appSiteID < configPath < locationConfigPath [< configPath < fileName]+ // ArrayList filePaths = new ArrayList(); filePaths.Add(VirtualPath.GetVirtualPathString(appPath)); filePaths.Add(appSiteName); filePaths.Add(appSiteID); filePaths.Add(configPath); filePaths.Add(locationConfigPath); string dummySiteID; VirtualPath virtualPath; WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(configPath, out dummySiteID, out virtualPath); // pathmap for machine.config filePaths.Add(WebConfigurationHost.MachineConfigPath); filePaths.Add(HttpConfigurationSystem.MachineConfigurationFilePath); // pathmap for root web.config if (webLevel != WebLevel.Machine) { filePaths.Add(WebConfigurationHost.RootWebConfigPath); filePaths.Add(HttpConfigurationSystem.RootWebConfigurationFilePath); // pathmap for other paths for (VirtualPath currentVirtualPath = virtualPath; currentVirtualPath != null; currentVirtualPath = currentVirtualPath.Parent) { string currentConfigPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(appSiteID, currentVirtualPath); string currentFilePath = configMapPath.MapPath(appSiteID, currentVirtualPath.VirtualPathString); currentFilePath = System.IO.Path.Combine(currentFilePath, HttpConfigurationSystem.WebConfigFileName); filePaths.Add(currentConfigPath); filePaths.Add(currentFilePath); } } // join into a single string StringBuilder sb = new StringBuilder(); for (int i = 0; i < filePaths.Count; i++) { if (i > 0) { sb.Append(FilePathsSeparatorChar); } string part = (string)filePaths[i]; sb.Append(part); } return(sb.ToString()); }
HostingPreferredMapPath(IConfigMapPath iisConfigMapPath, IConfigMapPath hostingConfigMapPath) { _iisConfigMapPath = iisConfigMapPath; _hostingConfigMapPath = hostingConfigMapPath; }
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; } } } }
public FakeHttpWorkerRequest(dynamic data, IApplicationHost appHost) { this.applicationHost = appHost; this.mapPath = this.applicationHost.GetConfigMapPathFactory().Create(null, null); this.data = data; }
internal static void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath, out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath) { appPath = null; appSiteName = null; appSiteID = null; if ((webLevel == WebLevel.Machine) || (virtualPath == null)) { if (!string.IsNullOrEmpty(site) && string.IsNullOrEmpty(locationSubPath)) { throw System.Web.Util.ExceptionUtil.ParameterInvalid("site"); } if (webLevel == WebLevel.Machine) { configPath = "machine"; } else { configPath = "machine/webroot"; } } else { if (!string.IsNullOrEmpty(site)) { configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID); if (string.IsNullOrEmpty(appSiteID)) { throw new InvalidOperationException(System.Web.SR.GetString("Config_failed_to_resolve_site_id", new object[] { site })); } } else { if (HostingEnvironment.IsHosted) { appSiteName = HostingEnvironment.SiteNameNoDemand; appSiteID = HostingEnvironment.SiteID; } if (string.IsNullOrEmpty(appSiteID)) { configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID); } } configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath); } locationConfigPath = null; string siteID = null; VirtualPath vpath = null; if (locationSubPath != null) { locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath); GetSiteIDAndVPathFromConfigPath(locationConfigPath, out siteID, out vpath); if (string.IsNullOrEmpty(appSiteID) && !string.IsNullOrEmpty(siteID)) { configMapPath.ResolveSiteArgument(siteID, out appSiteName, out appSiteID); if (!string.IsNullOrEmpty(appSiteID)) { locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, vpath); } else if ((vpath == null) || (vpath.VirtualPathString == "/")) { appSiteName = siteID; appSiteID = siteID; } else { appSiteName = null; appSiteID = null; } } } string appPathForPath = null; if (vpath != null) { appPathForPath = configMapPath.GetAppPathForPath(appSiteID, vpath.VirtualPathString); } else if (virtualPath != null) { appPathForPath = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString); } if (appPathForPath != null) { appPath = VirtualPath.Create(appPathForPath); } }
private HostingPreferredMapPath(IConfigMapPath iisConfigMapPath, IConfigMapPath hostingConfigMapPath) { this._iisConfigMapPath = iisConfigMapPath; this._hostingConfigMapPath = hostingConfigMapPath; }
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; } } } }
// // Set this configuration system to the default for requests ConfigurationManager.GetSection // static internal void EnsureInit(IConfigMapPath configMapPath, bool listenToFileChanges, bool initComplete) { if (!s_inited) { lock (s_initLock) { if (!s_inited) { s_initComplete = initComplete; // Use the IIS map path if one is not explicitly provided if (configMapPath == null) { configMapPath = IISMapPath.GetInstance(); } s_configMapPath = configMapPath; Type typeConfigSystem = Type.GetType(ConfigSystemTypeString, true); s_configSystem = (IConfigSystem)Activator.CreateInstance(typeConfigSystem, true); s_configSystem.Init( typeof(WebConfigurationHost), // The config host we'll create and use // The remaining parameters are passed to the config host: true, // Use the supplied configMapPath s_configMapPath, // the configMapPath to use null, // ConfigurationFileMap HostingEnvironment.ApplicationVirtualPath, // app path HostingEnvironment.SiteNameNoDemand, // app site name HostingEnvironment.SiteID); // app site ID s_configRoot = s_configSystem.Root; s_configHost = (WebConfigurationHost)s_configSystem.Host; // Register for config changed notifications HttpConfigurationSystem configSystem = new HttpConfigurationSystem(); if (listenToFileChanges) { s_configRoot.ConfigChanged += new InternalConfigEventHandler(configSystem.OnConfigurationChanged); } // Set the configSystem into the ConfigurationManager class. // Please note that factory.SetConfigurationSystem will end up calling // ConfigurationManager.SetConfigurationSystem, which is an internal static method // in System.Configuration.dll. If we want to call that here, we have to use // reflection and that's what we want to avoid. Type typeFactory = Type.GetType(InternalConfigSettingsFactoryTypeString, true); s_configSettingsFactory = (IInternalConfigSettingsFactory)Activator.CreateInstance(typeFactory, true); s_configSettingsFactory.SetConfigurationSystem(configSystem, initComplete); // The system has been successfully set, so mark that we should use it. s_httpConfigSystem = configSystem; // Mark as having completed initialization after s_httpConfigSystem has been set. // s_inited is coordinated with s_httpConfigSystem in UseHttpConfigurationSystem. s_inited = true; } } } Debug.Assert(s_httpConfigSystem != null, "s_httpConfigSystem != null - The appdomain is using the client configuration system."); }