views:

1024

answers:

4

Hi everyone.

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  A: 

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

John Saunders
+1: the simplest solutions are usually the best.
Joe
Thanks for the input - although I was looking for a setting somewhere :)
Ev
@Downvoter: care to explain the vote, or are you just a coward?
John Saunders
+1  A: 

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

Gulzar
+3  A: 

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

jellomonkey
You can also set this through code, so I guess that would only affect the current application: http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.restartonexternalchanges.aspx
Zhaph - Ben Duguid
@jellomonkey. Thanks for the help mate. The machine.config change worked. I should point out that it did not work with file="file.name" so it looks like it is neccessary to use configSource="file.name".Thanks again!
Ev
+1  A: 

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.

patmortech
I don't see where he said he was making the changes in code.
John Saunders
I didn't say making changes--I said ACCESSING the values through code. Most of us put things in appSettings because we want to use the value in our code. When I use the method above to retrieve the value any changes I have made to the external appsettings appear without restarting the app.
patmortech
Immediately available without restarting an ASP.NET application? I didn't think this was possible. I thought that AppSettings was cached per AppDomain, so it would be necessary to do an ASP.NET Application restart, in order to get a new AppDomain with the new settings.
John Saunders
Yup - the RestarOnExternalChanges in the machine.config is correct. One important thing to note, as jellomonkey pointed out, is that you need to reference the external file as configSource="file.name" not file="file.name". Thank you for the point in the right direction @patmortech.
Ev