Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing AppSetting does not have effect on Application

Tags:

c#

asp.net

In one of the application i am developing on ASP.Net. In this application we have been using lots of AppSettings. In the initial development we used ConfigurationManager.AppSettings[""]. but as development progressed we created a utility class in which we would define a static property for each AppSettings. Then issues started to come. Now when application is deployed on testing server and we change any settings on AppSettings it does not have any effect unless we restart the IIS. here is the following code snippet i am using to create static property of AppSettings.

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

One of the reason i could think of is that , It is a static property so it may be initialized once in its lifetime so next time onwards it may not be fetching values from appsettings .

like image 533
Chintan Shah Avatar asked Dec 10 '22 12:12

Chintan Shah


1 Answers

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

If you use:

<appSettings file="AppSettings.config" />

Then changes to the external file will not be available until a change to web.config is made or a restart is performed.

But if you change that to:

<appSettings configSource="AppSettings.config" />

The changes to those settings are available in your code immediately without a restart or a web.config change.

I just verified that this is the case with a repeatable test.

like image 107
Ed DeGagne Avatar answered Jan 19 '23 01:01

Ed DeGagne