dlopezgonzalez
dlopezgonzalez

Reputation: 4297

ConfigurationManager is not refreshing the AppSettings after a new execution

In my web application (c# + asp.net) I can use my new values on my config file (install.properties) when I try to get the values using "ConfigurationManager".

String pathJava = ConfigurationManager.AppSettings["FilePathJava"];

I have got this in my install.properties

<add key="FilePathJava" value="C:\Program Files\Java\jre7\bin\java.exe"></add>

I rode that I can do this to refresh the values:

ConfigurationManager.RefreshSection("appSettings");

I also I did this:

ConfigurationManager.OpenMachineConfiguration()

But the value does not change.

Also I tried to add a new key, but the ConfigurationManager returns me a null value.

Upvotes: 2

Views: 1980

Answers (1)

Dominic Zukiewicz
Dominic Zukiewicz

Reputation: 8464

You have a potential problem...

If you change any value in the Web.config, while the site is running, it will reset the web site. Any modification whatsoever to this files causes an IIS reset to occur.

A solution to what you want, without resetting the web site is to move the application settings out of Web.config altogether:

<?xml version="1.0"?>
<configuration>
   <appSettings configSource="appSettings.config"/>
</configuration>

And now place your appSettings in the appSettings.config file:

<?xml version="1.0"?>
<appSettings>
  <add key="FilePathJava" value="C:\Program Files\Java\jre7\bin\java.exe"/>
</appSettings>

Now, you can still use the ConfigurationManager.AppSettings["FilePathJava"], and your ConfigurationManager.RefreshSection("appSettings") should work as well.

Upvotes: 1

Related Questions