David
David

Reputation: 900

In Visual Studio 2008 - how long before a web.config change "takes"?

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?

Upvotes: 2

Views: 2512

Answers (6)

roundcrisis
roundcrisis

Reputation: 17806

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

Upvotes: 0

John Saunders
John Saunders

Reputation: 161821

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.

Upvotes: 5

Zaffiro
Zaffiro

Reputation: 4934

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!

Upvotes: 0

Josh
Josh

Reputation: 8477

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.

Upvotes: 4

NinethSense
NinethSense

Reputation: 9028

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.

Upvotes: 2

George Stocker
George Stocker

Reputation: 57907

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

Upvotes: 1

Related Questions