msview msview - 14 days ago 6
ASP.NET (C#) Question

Are external config sections in web.config cached?

I have my own custom configuration section, like this

<configSections>
<section name="ConnectionStrings"
type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
restartOnExternalChanges="false"
requirePermission="false" />
</configSections>


and I keep it in an external file like this

<ConnectionStrings configSource="connections.config"/>


I know that web.config is cached, and when I change the config, IIS resets the cache and reread the config again after restart...

But In my case, when I change my external config
connections.config
IIS doesn't restart the app because I set
restartOnExternalChanges="false"
.

Question: Is my external config cached as well? or IIS reads from it all the time when I use
ConfigurationManager.GetSection("ConnectionStrings")
?

Answer

Sure, it is cached as well. The API ConfigurationManager.GetSection provides read-only view of the underlying configuration settings.