Working with Multiple Web Config C#

Posted by Hiyasat on Stack Overflow See other posts from Stack Overflow or by Hiyasat
Published on 2010-05-03T12:00:16Z Indexed on 2010/05/03 12:08 UTC
Read the original article Hit count: 163

Filed under:

Hi All, I have 2 projects, each one have a WebConfig file, and i want to edit the 2 webconfig files from one place, and i try to do this:

    string configPath = "/";
    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();
    }

The problem that confProtocol is set to empty.

How to set The WebConfig path of the Protocol Project from the UI Project?

© Stack Overflow or respective owner

Related posts about c#