0

I made some tests in a console application and all is working properly.

After calling:

ConfigurationManager.RefreshSection("appSettings");

I'm able to access settings with ConfigurationManager.AppSettings and I receive the new value.

Unfortunately using a site seems not working and I continue to read the old values.

Of course, I use an ExternalWeb.config to avoid that the site will restart changing the Web.config:

<appSettings file="ExternalWeb.config">

Anyway is the same configuration that I made using the App.config and in that case worked.

Is possible to use ConfigurationManager.RefreshSection with a web config? If yes, where could be the problem?

I'm using .Net Framework 4.8.

user1812102
  • 51
  • 1
  • 6

1 Answers1

0

After some research is confirmed that ConfigurationManager.RefreshSection cannot be used with web apps.

I found a solution that can fit my needs and I want to share in order to help other people that can have a similar issue.

https://learn.microsoft.com/it-it/dotnet/api/system.web.configuration.webconfigurationmanager.openwebconfiguration

string file = @"/ExternalWeb.config";
System.Configuration.Configuration config =
       WebConfigurationManager.OpenWebConfiguration(file)
       as System.Configuration.Configuration;

KeyValueConfigurationCollection appSettings =
     config.AppSettings.Settings;

string keys = string.Empty;
foreach (string key in appSettings.AllKeys)
{
    keys = keys + key + "_" + appSettings[key].Value +"\r\n"; 
}

In this way I can read my external web config (I don't want that the web app reload after changes, so I prefer to change an external config)

user1812102
  • 51
  • 1
  • 6