在其中一个应用程序中,我正在ASP.Net上进行开发.在此应用程序中,我们一直在使用许多AppSettings.在最初的开发中,我们使用了ConfigurationManager.AppSettings ["].但是随着开发的进行,我们创建了一个实用程序类,其中我们将为每个AppSettings定义一个静态属性.然后问题开始出现.现在,当应用程序部署在测试服务器上并且我们更改AppSettings上的任何设置时,除非重新启动IIS,否则它没有任何作用.这是我用来创建AppSettings静态属性的以下代码段.
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"]; } } }我能想到的原因之一是,它是一个静态属性,因此可以在其生命周期中进行一次初始化,因此下一次起,它可能不会从appsettings中获取值.
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 .
推荐答案我知道这是一个旧线程,但是需要添加一些东西.
I know this is an old thread, but something to add.
如果您使用:
<appSettings file="AppSettings.config" />然后对外部文件的更改将不可用,直到对web.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" />对这些设置所做的更改可立即在您的代码中使用,而无需重新启动或更改web.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.
更多推荐
更改AppSetting对应用程序没有影响
发布评论