Пример #1
0
        /// <summary>
        /// 获取标准Web应用程序的配置信息,合并Web.config和global配置文件
        /// </summary>
        /// <param name="machineConfigPath">global配置文件地址</param>
        /// <param name="ignoreFileNotExist">是否忽略不存在的文件</param>
        /// <param name="globalConfig">返回的全局配置</param>
        /// <param name="fileDependencies">缓存依赖文件</param>
        /// <returns>Web.config和global配置文件合并后的Configuration对象</returns>
        private static System.Configuration.Configuration GetStandardWebAndGlobalConfiguration(string machineConfigPath, bool ignoreFileNotExist, out System.Configuration.Configuration globalConfig, params string[] fileDependencies)
        {
            string cacheKey = ConfigurationBroker.CreateConfigurationCacheKey(machineConfigPath);

            System.Configuration.Configuration config;
            globalConfig = null;

            WebConfigurationFileMap fileMap = new WebConfigurationFileMap();

            fileMap.MachineConfigFilename = machineConfigPath;
            VirtualDirectoryMapping vDirMap = new VirtualDirectoryMapping(
                HostingEnvironment.ApplicationPhysicalPath,
                true);

            fileMap.VirtualDirectories.Add("/", vDirMap);

            if (ConfigurationCache.Instance.TryGetValue(cacheKey, out config) == false)
            {
                config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "/",
                                                                            HostingEnvironment.SiteName);

                Array.Resize <string>(ref fileDependencies, fileDependencies.Length + 1);
                fileDependencies[fileDependencies.Length - 1] = machineConfigPath;

                ConfigurationBroker.AddConfigurationToCache(cacheKey, config, ignoreFileNotExist, fileDependencies);
            }

            globalConfig = GetGlobalConfiguration(machineConfigPath, ignoreFileNotExist,
                                                  () => WebConfigurationManager.OpenMappedMachineConfiguration(fileMap),
                                                  fileDependencies);

            return(config);
        }
Пример #2
0
        public void OpenMappedMachineConfiguration()
        {
            ConfigurationFileMap map = new ConfigurationFileMap();

            _Configuration c1 = WebConfigurationManager.OpenMappedMachineConfiguration(map, "clientTest");
            _Configuration c2 = ConfigurationManager.OpenMappedMachineConfiguration(map);

            Assert.AreEqual(c1.FilePath, c2.FilePath, "A1");
        }
Пример #3
0
        // same stack trace for OpenWebConfiguration_siteNull2_absolutePath.
        public void OpenMappedMachineConfiguration_absolute()
        {
            ConfigurationFileMap map = new ConfigurationFileMap();

            WebConfigurationManager.OpenMappedMachineConfiguration(map, "/clientTest");
        }