Using configurationmanager to read from multiple web.config files

前端 未结 2 1685
灰色年华
灰色年华 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!

提交回复
热议问题