public static object GetWebApplicationSection(string sectionName) { if (HttpConfigurationSystem.UseHttpConfigurationSystem) { return(HttpConfigurationSystem.GetApplicationSection(sectionName)); } return(ConfigurationManager.GetSection(sectionName)); }
public static object GetSection(string sectionName, string path) { if (!HttpConfigurationSystem.UseHttpConfigurationSystem) { throw new InvalidOperationException(System.Web.SR.GetString("Config_GetSectionWithPathArgInvalid")); } return(HttpConfigurationSystem.GetSection(sectionName, path)); }
public static object GetSection(string sectionName, string path) { if (HttpConfigurationSystem.UseHttpConfigurationSystem) { return(HttpConfigurationSystem.GetSection(sectionName, path)); } else { throw new InvalidOperationException(SR.GetString(SR.Config_GetSectionWithPathArgInvalid)); } }
object IConfigurationSystem.GetConfig(string configKey) { HttpContext context = HttpContext.Current; if (context != null) { return(context.GetConfig(configKey)); } // if no context is available we assume application-level configuration HttpConfigurationRecord applicationLevelConfigRecord = HttpConfigurationSystem.GetComplete(); return(applicationLevelConfigRecord.GetConfig(configKey)); }
internal static void Init() { lock (lockobj) { if (config != null) { return; } /* deal with the ConfigurationSettings stuff */ { Web20DefaultConfig settings = Web20DefaultConfig.GetInstance(); Type t = typeof(ConfigurationSettings); MethodInfo changeConfig = t.GetMethod("ChangeConfigurationSystem", privStatic); if (changeConfig == null) { throw new ConfigurationException("Cannot find method CCS"); } object [] args = new object [] { settings }; oldConfig = (IConfigurationSystem)changeConfig.Invoke(null, args); config = settings; config.Init(); } /* deal with the ConfigurationManager stuff */ { HttpConfigurationSystem system = new HttpConfigurationSystem(); Type t = typeof(ConfigurationManager); MethodInfo changeConfig = t.GetMethod("ChangeConfigurationSystem", privStatic); if (changeConfig == null) { throw new ConfigurationException("Cannot find method CCS"); } object [] args = new object [] { system }; changeConfig.Invoke(null, args); //configSystem = system; } } }
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; } } } }
internal static void EnsureInit() { lock (typeof(HttpConfigurationSystemBase)) { if (_system == null) { _system = new HttpConfigurationSystem(); // // Use reflection to do equivalent of: // // ConfigurationSettings.SetConfigurationSystem(_system); // // This allows SetConfigurationSystem to be internal but still set by ASP.NET // MethodInfo method = typeof(ConfigurationSettings).GetMethod("SetConfigurationSystem", BindingFlags.Static | BindingFlags.NonPublic); if (method == null) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Config_unable_to_set_configuration_system)); } method.Invoke(null, new object [] { _system }); } } }
/// <include file='doc\HttpConfigurationSystem.uex' path='docs/doc[@for="HttpConfigPerf.FlushConfig"]/*' /> public static void FlushConfig(string path) { HttpConfigurationSystem.FlushConfig(path); }
// // ResolveFiles - parse files referenced with <file src="" /> // static void ResolveFiles(ParseState parseState, object configurationContext) { // // 1) get the directory of the configuration file currently being parsed // HttpConfigurationContext httpConfigurationContext = (HttpConfigurationContext)configurationContext; string configurationDirectory = null; bool useAssert = false; // // Only assert to read cap files when parsing machine.config // (allow device updates to work in restricted trust levels). // // Machine.config can be securely identified by the context being // an HttpConfigurationContext with null path. // try { if (httpConfigurationContext.VirtualPath == null) { useAssert = true; // we need to assert here to get the file path from ConfigurationException FileIOPermission fiop = new FileIOPermission(PermissionState.None); fiop.AllFiles = FileIOPermissionAccess.PathDiscovery; fiop.Assert(); } Pair pair0 = (Pair)parseState.FileList[0]; XmlNode srcAttribute = (XmlNode)pair0.Second; configurationDirectory = Path.GetDirectoryName(ConfigurationErrorsException.GetFilename(srcAttribute)); } finally { if (useAssert) { CodeAccessPermission.RevertAssert(); } } // // 2) iterate through list of referenced files, builing rule lists for each // foreach (Pair pair in parseState.FileList) { string srcFilename = (string)pair.First; string fullFilename = Path.Combine(configurationDirectory, srcFilename); XmlNode section; try { if (useAssert) { InternalSecurityPermissions.FileReadAccess(fullFilename).Assert(); } Exception fcmException = null; try { HttpConfigurationSystem.AddFileDependency(fullFilename); } catch (Exception e) { fcmException = e; } ConfigXmlDocument configDoc = new ConfigXmlDocument(); try { configDoc.Load(fullFilename); section = configDoc.DocumentElement; } catch (Exception e) { throw new ConfigurationErrorsException(SR.GetString(SR.Error_loading_XML_file, fullFilename, e.Message), e, (XmlNode)pair.Second); } if (fcmException != null) { throw fcmException; } } finally { if (useAssert) { // Cannot apply next FileReadAccess PermissionSet unless // current set is explicitly reverted. Also minimizes // granted permissions. CodeAccessPermission.RevertAssert(); } } if (section.Name != parseState.SectionName) { throw new ConfigurationErrorsException(SR.GetString(SR.Capability_file_root_element, parseState.SectionName), section); } HandlerBase.CheckForUnrecognizedAttributes(section); ArrayList sublist = RuleListFromElement(parseState, section, true); if (sublist.Count > 0) { parseState.RuleList.Add(new CapabilitiesSection(CapabilitiesRule.Filter, null, null, sublist)); } } }
private static void ResolveFiles(ParseState parseState, object configurationContext) { HttpConfigurationContext context = (HttpConfigurationContext)configurationContext; string directoryName = null; bool flag = false; try { if (context.VirtualPath == null) { flag = true; new FileIOPermission(PermissionState.None) { AllFiles = FileIOPermissionAccess.PathDiscovery }.Assert(); } Pair pair = (Pair)parseState.FileList[0]; XmlNode second = (XmlNode)pair.Second; directoryName = Path.GetDirectoryName(ConfigurationErrorsException.GetFilename(second)); } finally { if (flag) { CodeAccessPermission.RevertAssert(); } } foreach (Pair pair2 in parseState.FileList) { XmlNode documentElement; string first = (string)pair2.First; string filename = Path.Combine(directoryName, first); try { if (flag) { InternalSecurityPermissions.FileReadAccess(filename).Assert(); } Exception exception = null; try { HttpConfigurationSystem.AddFileDependency(filename); } catch (Exception exception2) { exception = exception2; } ConfigXmlDocument document = new ConfigXmlDocument(); try { document.Load(filename); documentElement = document.DocumentElement; } catch (Exception exception3) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Error_loading_XML_file", new object[] { filename, exception3.Message }), exception3, (XmlNode)pair2.Second); } if (exception != null) { throw exception; } } finally { if (flag) { CodeAccessPermission.RevertAssert(); } } if (documentElement.Name != parseState.SectionName) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Capability_file_root_element", new object[] { parseState.SectionName }), documentElement); } System.Web.Configuration.HandlerBase.CheckForUnrecognizedAttributes(documentElement); ArrayList rulelist = RuleListFromElement(parseState, documentElement, true); if (rulelist.Count > 0) { parseState.RuleList.Add(new CapabilitiesSection(2, null, null, rulelist)); } } }
internal static void Init () { lock (lockobj) { if (config != null) return; /* deal with the ConfigurationSettings stuff */ { Web20DefaultConfig settings = Web20DefaultConfig.GetInstance (); Type t = typeof (ConfigurationSettings); MethodInfo changeConfig = t.GetMethod ("ChangeConfigurationSystem", privStatic); if (changeConfig == null) throw new ConfigurationException ("Cannot find method CCS"); object [] args = new object [] {settings}; oldConfig = (IConfigurationSystem)changeConfig.Invoke (null, args); config = settings; config.Init (); } /* deal with the ConfigurationManager stuff */ { HttpConfigurationSystem system = new HttpConfigurationSystem (); Type t = typeof (ConfigurationManager); MethodInfo changeConfig = t.GetMethod ("ChangeConfigurationSystem", privStatic); if (changeConfig == null) throw new ConfigurationException ("Cannot find method CCS"); object [] args = new object [] {system}; changeConfig.Invoke (null, args); //configSystem = system; } } }
// // 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."); }
// // 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."); }
// // Return the config object for the current context. // If the HttpContext is not available, get the config object // for the web application path. // object IInternalConfigSystem.GetSection(string configKey) { return(HttpConfigurationSystem.GetSection(configKey)); }