Using configurationmanager to read from multiple web.config files

前端 未结 2 1684
灰色年华
灰色年华 2021-01-17 19:12

Background:

I have some data thats stored in the web.config files of about 100 web applications. This data is getting moved to a database gradually.

相关标签:
2条回答
  • 2021-01-17 19:21

    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!

    0 讨论(0)
  • 2021-01-17 19:25

    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?

    0 讨论(0)
提交回复
热议问题