views:

472

answers:

6

I have some settings in a web.config file that I want to override when I'm testing the ASP.NET app locally on my machine. The main part looks like this:

  <appSettings file="WebAppSettings.config">
    <add key="DEBUG" value ="False"/>
    <add key="PROD" value="TrueInMainConfigFile"/>
  </appSettings>

Now, in my local "WebAppSettings.config" I have:

<appSettings>
  <remove key="DEBUG"/>
  <remove key="PROD"/>
  <add key="DEBUG" value ="True"/>
  <add key="PROD" value="False"/>
</appSettings>

I had JUST changed the value of "PROD" from True to False and saved the file. Yet, when I rebuild and run the site (again, on my local machine with IIS, not Cassini), the value of System.Configuration.ConfigurationManager.AppSettings("PROD") still returns "True" instead of "False".

Sometimes letting it "sit for a long time" solves this problem. However, for the most part, I have to close and re-open VS2008 in order to get the new value to 'take'.

What's going on here?

+1  A: 

If I reload the site when I'm working off of IIS, any changes are propagated immediately. Not sure what to tell you.

George Stocker
+2  A: 

A change in web.config takes:

  • On Visual Studio, the next time you run (F5)
  • Production/direct edit - next time you invoke the appilcation

Dynamic building takes place whenever the system detects a change in your \bin folder or configuration file.

NinethSense
+2  A: 

If you update the web.config, the next session will start using the new values. If you're updating a secondary file, that might be the reason you're not seeing it. Try changing anything in the web.config, such as adding a space, and saving the file.

Josh
That's EXACTLY the reason. I changed the secondary file and the new value was not reflected. When I changed the actual web.config file, it reloaded everything, including the new value from the secondary file.So now I have a new "gotcha" to keep an eye out for in Visual Studio - when editing secondary web config files, always make sure you force a reload of the main web.config - anything that causes the file to be saved - as you suggested, adding a space was sufficient.
David
A: 

Saving the Web.config file will recycle the application and load the new values. Are you sure your modifying the right file? The comment "with IIS, not Cassini)" could mean you have a published/separate version in IIS?

Hope this helps!

Zaffiro
A: 

Changing web.config recycles the AppDomain application pool so the changes should be seen immediately.

Are you are doing the change to web.config within the application? If so the story is different because web.config is cached

So you have a few options

1) Have this setting in a different file 2) use ConfigurationManager.AppSettings["MyAppSetting"] I remember some version of the ConfigurationManager being deprecated, but there is a replacement, oh yes and you have to refresh the section

Hope it helps

Miau
+3  A: 

Did you make your changes to web.config, or to WebAppSettings.config? A change to web.config immediately recycles the AppDomain, which results in the new values being used as soon as they're requested. A change to WebAppSettings.config does nothing.

John Saunders