Inheritance: System.Configuration.ConfigurationSection
Beispiel #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 ConnectionSection 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 ConnectionSection;
                }
                else
                {
                    m_section = WebConfigurationManager.GetSection(definedName)
                                as ConnectionSection;
                    cfgFileName = "web.config";
                }

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

            return(m_section);
        }
        /// <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 ConnectionSection 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 ConnectionSection;
                }
                else
                {
                    m_section = WebConfigurationManager.GetSection(definedName)
                                as ConnectionSection;
                    cfgFileName = "web.config";
                }

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

            return m_section;
        }