I have 2 projects, each of which has a WebConfig file, and I want to edit 2 webconfig files from one place, and I'm trying to do this:
string configPath = "/WebSite Name";
Configuration confUI = WebConfigurationManager.OpenWebConfiguration("~");
Configuration confProtocol = WebConfigurationManager.OpenWebConfiguration(configPath);
AppSettingsSection appSettingsUI = (AppSettingsSection)confUI.GetSection("appSettings");
AppSettingsSection appSettingsProtocol = (AppSettingsSection)confProtocol.GetSection("appSettings");
if (appSettingsUI != null & appSettingsProtocol != null)
{
appSettingsUI.Settings[key].Value = value;
appSettingsProtocol.Settings[key].Value = value;
confUI.Save();
confProtocol.Save();
}
Also i try
Configuration confProtocol = WebConfigurationManager.OpenWebConfiguration(configPath,"webSiteName");
The problem is that confProtocol is set to empty.
How to set WebConfig path of protocol project from user interface project?
source
share