Is IIsreset always neccessary when storing my Web.Config appsettings in a separate file?

末鹿安然 提交于 2020-05-08 15:30:52

问题


I've got an ASP.Net app in which my AppSettings node from the Web.Config xml is stored in a separate file.

So my Web.Config contains this:

<appSettings file="AppSettings.config" />

Whenever I change a setting in there I have to do an iisreset to force the changes to kick in. In other words, my changes in this file aren't detected the same way changes to the Web.Config is.

Does anyone know how I can make these changes take effect automatically, like it does with the Web.Config?

Thanks!


回答1:


Edit: In response to other answers. You can change the machine.config to include the restartOnExternalChanges="true" option for appSettings; however, this will cause ALL of your web applications to restart when you touch any of the external app settings files. (Also, I think this may only work when you use configSource="file.name" not file="file.name".)

This is by design and the only way to cause the application to reset is manually or via a script.

You can take a look here for a script which will reset your application without restarting iis:

http://weblogs.asp.net/jgalloway/archive/2006/06/01/Avoid-IISRESET-in-ASP.NET-applications-_2800_added-bonus_3A00_-ASPRESET_2900_.aspx




回答2:


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.




回答3:


Open web.config in notepad. Save it. Exit notepad.




回答4:


How are you accessing your app settings in code? I have an external appsettings file (though i use the configSource property instead of file) and any changes I make are immediately available when using ConfigurationManager.AppSettings("settingname") in code to get the value.

With that said, if you really do need an app restart for some other reason, and you have access to the machine.config file on the server, in the definition for the appSettings section, there is an attribute named RestartOnExternalChanges that can be set to true (defaults to false) and then the appSettings section will behave like you want it to, I believe.




回答5:


You can write a filewatcher service to monitor your custom config file. Issue iisrest command when the changed event gets executed inside the service.




回答6:


If you were to instead use ConfigurationRedirection (introduced with IIS 7), you could configure IIS to poll for changes to your external configuration file (starting with IIS 7.5). This would cover the whole .config file, though, not just the appSettings section.

This allows you to store configuration settings on a UNC server that all Web server computers in the Web farm can access.



来源:https://stackoverflow.com/questions/864200/is-iisreset-always-neccessary-when-storing-my-web-config-appsettings-in-a-separa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!