9

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. The webpages will show the web.config data until somebody clicks on an "edit" link in which case they'll be redirected to a webpage which will allow them to update this data where it will be saved in a database instead.

Problem:

Not all of the data will be changed on this page that will save it to the database. When somebody clicks the "edit" link I want the form to populate with the data from the web.config file and when they click "save" have it save to the database. However, using the configurationmanager I can only get it to pull data from the web.config file on current application.

Questions:

  1. Is there a way to use configurationmanager to select the web.config file from lets say ../{dynamic_app_id}/web.config ?
  2. is reading them as plain xml files my only option?
  3. Are there any pitfalls to this approach?
  4. Is there another solution that would work better perhaps?
4

2 回答 2

18

您可以轻松读取任何配置文件。请查看我从外部 app.config 文件中读取应用程序设置的示例代码:

        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;

快乐的编码和最好的问候!

于 2012-08-21T20:01:15.583 回答
0

您可以在 web.config 中添加以下部分

然后,在您的项目中添加“env”文件夹并将您的环境设置添加到 EnvironmentalSettings.config 中。您仍然可以使用 ConfigurationManager 从 EnvironmentalSettings 文件中获取设置。

这是否回答你的问题?

于 2012-08-21T20:04:05.653 回答