Using configurationmanager to read from multiple web.config files

人走茶凉 提交于 2019-12-01 15:59:18

You can read any config file with ease. Please see my sample code where I read application settings from external app.config file:

        System.Configuration.KeyValueConfigurationCollection settings;
        System.Configuration.Configuration config;

        System.Configuration.ExeConfigurationFileMap configFile = new System.Configuration.ExeConfigurationFileMap();
        configFile.ExeConfigFilename = "my_file.config";
        config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(configFile, System.Configuration.ConfigurationUserLevel.None);
        settings = config.AppSettings.Settings;

Happy coding and best regards!

You can add below section in your web.config

then, add "env" folder in your project and add your environmental settings into EnvironmentalSettings.config. And you can still use ConfigurationManager to get settings from EnvironmentalSettings file.

Does that answer your question?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!