Changing AppSetting Does Not Affect Application

In one application, I am developing ASP.Net. In this application, we have used many AppSettings. In the initial development, we used ConfigurationManager.AppSettings [""]. but as we developed, we created a utility class in which we would define a static property for each AppSettings. Then the problems began. Now that the application is deployed to the test server, and we change any settings in AppSettings, it has no effect if we do not restart IIS. here is the following piece of code that I use to create a static AppSettings property.

public static class AppSettingsUtil { public static string Log4Net { get { return ConfigurationManager.AppSettings["Log4Net"]; } } } 

One of the reasons I could think of this is that it is a static property, so it can be initialized once in my life, so the next time it may not extract values ​​from the appsettings settings.

+4
source share
3 answers

I know this is an old thread, but add something.

If you use:

 <appSettings file="AppSettings.config" /> 

Then the changes in the external file will be unavailable until the change in web.config is completed or a restart is made.

But if you change this to:

 <appSettings configSource="AppSettings.config" /> 

Changes to these parameters are available in your code immediately without restarting or changing web.config.

I just confirmed that this is the case with the repeated test.

+10
source

Obviously, you are deploying the configuration file because after restarting IIS an updated configuration is available.

It looks like you are using an external file for your AppSettings:

 <appSettings file="my-app-settings.config" /> 

This is useful for keeping web.config clean, especially if you support different configuration files for a separate environment (for example, dev, testing, prod). However, the catch of this approach is that ASP.NET does not automatically detect changes to the external file, so your settings are not updated automatically.

Per MSDN , changes to the .NET Framework 2.0 in a separate file do not restart subsequent applications. It looks like your solution would be to not use an external file in this scenario.

+3
source

Static methods in this context will never cache the value coming from the configuration without using one of the AOP frameworks. A more likely scenario is that the site does not compile or move to frame directories. In a personal note, I prefer to call this file Config.cs.

0
source

All Articles