Inheritance: System.Configuration.ConfigurationSection
コード例 #1
0
        /// <summary>
        /// Gets the configuration section using the specified element name.
        /// </summary>
        /// <remarks>
        /// If an HttpContext exists, uses the WebConfigurationManager
        /// to get the configuration section from web.config.
        /// </remarks>
        public static ParametersSection GetSection(string definedName)
        {
            if (m_section == null)
            {
                log.Debug(String.Format("Retrieving configuration section <{0}>", definedName));

                string cfgFileName = ".config";
                if (HttpContext.Current == null)
                {
                    m_section = ConfigurationManager.GetSection(definedName)
                                as ParametersSection;
                }
                else
                {
                    m_section = WebConfigurationManager.GetSection(definedName)
                                as ParametersSection;
                    cfgFileName = "web.config";
                }

                if (m_section == null)
                {
                    throw new ConfigurationErrorsException("The <" + definedName +
                                                           "> section is not defined in your " +
                                                           cfgFileName + " file!");
                }
            }

            return(m_section);
        }
コード例 #2
0
        /// <summary>
        /// Gets the configuration section using the specified element name.
        /// </summary>
        /// <remarks>
        /// If an HttpContext exists, uses the WebConfigurationManager
        /// to get the configuration section from web.config.
        /// </remarks>
        public static ParametersSection GetSection(string definedName)
        {
            if (m_section == null)
            {
                log.Debug(String.Format("Retrieving configuration section <{0}>", definedName));

                string cfgFileName = ".config";
                if (HttpContext.Current == null)
                {
                    m_section = ConfigurationManager.GetSection(definedName)
                                as ParametersSection;
                }
                else
                {
                    m_section = WebConfigurationManager.GetSection(definedName)
                                as ParametersSection;
                    cfgFileName = "web.config";
                }

                if (m_section == null)
                    throw new ConfigurationErrorsException("The <" + definedName +
                      "> section is not defined in your " +
                      cfgFileName + " file!");
            }

            return m_section;
        }