[英]Using configurationmanager to read from multiple web.config files
Background: 背景:
I have some data thats stored in the web.config files of about 100 web applications. 我有一些数据存储在大约100个Web应用程序的web.config文件中。 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. 网页将显示web.config数据,直到有人点击“编辑”链接,在这种情况下,他们将被重定向到一个网页,这将允许他们更新这些数据,而不是将其保存在数据库中。
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. 当有人点击“编辑”链接时,我希望表单填充来自web.config文件的数据,当他们点击“保存”时,它会保存到数据库中。 However, using the configurationmanager I can only get it to pull data from the web.config file on current application. 但是,使用配置管理器我只能从当前应用程序的web.config文件中提取数据。
Questions: 问题:
../{dynamic_app_id}/web.config
? 有没有办法使用configurationmanager来选择web.config文件,比如说../{dynamic_app_id}/web.config
? You can read any config file with ease. 您可以轻松读取任何配置文件。 Please see my sample code where I read application settings from external app.config file: 请参阅我的示例代码,其中我从外部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;
Happy coding and best regards! 快乐的编码和最好的问候!
You can add below section in your web.config 您可以在web.config中添加以下部分
then, add "env" folder in your project and add your environmental settings into EnvironmentalSettings.config. 然后,在项目中添加“env”文件夹,并将环境设置添加到EnvironmentalSettings.config中。 And you can still use ConfigurationManager to get settings from EnvironmentalSettings file. 您仍然可以使用ConfigurationManager从EnvironmentalSettings文件中获取设置。
Does that answer your question? 这是否回答你的问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.