Banshee
Banshee

Reputation: 15827

Set configurations in runtime without restart of service?

When creating a webapplication we get a web.config file, if we edit this config file the webapplication will restart.

There is a way to reference another config file in .NET but will this solve the problem?

<appSettings configSource="Config\AppSettings.config"/>
  1. If I change and save the AppSettings.config, will the service continue to run without stop?
  2. How will we get the configurations located in AppSEttings.config from within the code?
  3. If we ask after a specific setting located in AppSettings.config 1000 times in 1 sec, will .NET read the file every time or will to use some kind of cache? And if so listen on changes in AppSettings.config file to do a clear of this cache?

Upvotes: 0

Views: 903

Answers (3)

Reg Edit
Reg Edit

Reputation: 6924

Consider storing (some) settings in a database instead of web.config.

Upvotes: 0

user2316116
user2316116

Reputation: 6814

The appSettings key supports two attributes for external configuration: file and configSource (inherited)

<appSettings file="AppSettings.config" />
<appSettings configSource="AppSettings.config" />

In both cases changing the external file does not restart the worker process, see http://msdn.microsoft.com/en-us/library/ms228154(v=vs.100).aspx and http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx (for configSource there is a RestartOnExternalChanges property that forces a restart on change)

Read more at Changing AppSetting does not have effect on Application and Is web.config or app.config cached in memory

To access the settings use

WebConfigurationManager.AppSettings["key_name"]

Upvotes: 1

kemals
kemals

Reputation: 226

1) if you phsically change web.config then service will restart, but if you change programmatically then it will not restart, so you needn't have another web.config, you can do it programmatically. 2) You can read here 3) It is cached, read one time in application start event

Upvotes: 0

Related Questions