开发者

Is web.config or app.config cached in memory

i开发者_StackOverflow中文版f it is cached, what happens if I use multiple web.config in multi-level folders


They all get cached.

Configuration is read once, at startup. With web.config, IIS watches for file changes and restarts the application.


OK, so ya'll are missing a KEY feature in the Web.Config file's area.

Yes, web.config is cached and changing contents of the file will restart your web app. And, all your connected users will not be happy, too, because they'll need to "reconnect" a-new, possibly losing desired information.

So, use an EXTERNAL custom file for your AppSettings, as follows:

<appSettings configSource="MyCustom_AppSettings.config"/>

Then, in the file MyCustom_AppSettings.config file, you have your settings, as such this example has:

<appSettings>

  <!--   AppSecurity Settings   -->
  <add key="AppStatus_Active" value="Active"/>

  <!--   Application Info Settings   -->
  <add key="AppID" value="25"/>
  <add key="AppName" value="MyCoolApp"/>
  <add key="AppVersion" value="20120307_162344"/>
</appSettings>

Now, if you need to add, change, or remove an AppSetting, when you change it in this file the change is nearly instant in your web-app BUT (and here's the BEST part), your app DOES NOT RESTART!

Everything stays kosher except those settings you've added/modified/removed in the external .config file.

And, yes, the same thing can done for the section as follows:

<connectionStrings configSource="MyCustomApp_ConnectionStrings.config"/>

and the file MyCustomApp_ConnectionStrings.config has all the connection strings you need. Change a connection string in the external .config file and it starts getting used right away and with no web-app restart.

The configSource setting(s) are great when you need to deploy to development, testing, and production on different boxes and need settings pertinent to that given box/environment.

So, now ya know (something that's been around for 7+ years).

It's That Simple. Really.

KC


Web.config (excluding external config files) is read when the application loads. Some config settings have a cascading behavior. For example, the system.web/authorization section can be overridden by configs at deeper levels.

ASP.NET monitors the web.config for changes. When it changes, the web application is forced to restart. Moral is that web.config settings are cached for the life of the application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜