使用ConfigurationManager中从多个web.config文件中读取 [英] Using configurationmanager to read from multiple web.config files
问题描述
背景:
我在存储约100 Web应用程序的web.config文件中的一些数据,多数民众赞成。这个数据是越来越移到数据库逐步显现。该网页将显示在web.config数据,直到有人点击编辑链接在这种情况下,他们会被重定向到一个网页,这将使他们能够更新这一数据在那里将被保存在一个数据库来代替。
问题:
并非所有数据都将这个页面,将其保存到数据库中进行更改。当有人点击编辑链接,我希望表单从web.config文件中的数据填充,当他们点击保存把它保存到数据库中。但是,使用ConfigurationManager中,我只能得到它从当前应用程序的web.config文件中提取数据。
问题:
- 有没有办法使用ConfigurationManager中选择web.config文件从可以说
../ {} dynamic_app_id /web.config
? 办法 - 是阅读他们作为普通的XML文件,我唯一的选择?
- 是否有任何陷阱,以这种方式?
- 有另一种解决方案,能够更好地工作吧?
您可以阅读轻松的配置文件。请参阅我的样品code,其中我读到从外部app.config文件的应用程序设置:
System.Configuration.KeyValueConfigurationCollection设置;
System.Configuration.Configuration配置; System.Configuration.ExeConfigurationFileMap CONFIGFILE =新System.Configuration.ExeConfigurationFileMap();
configFile.ExeConfigFilename =my_file.config;
配置= System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(CONFIGFILE,System.Configuration.ConfigurationUserLevel.None);
设置= config.AppSettings.Settings;
快乐编码和最诚挚的问候!
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:
- Is there a way to use configurationmanager to select the web.config file from lets say
../{dynamic_app_id}/web.config
? - is reading them as plain xml files my only option?
- Are there any pitfalls to this approach?
- Is there another solution that would work better perhaps?
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!
这篇关于使用ConfigurationManager中从多个web.config文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!