Reputation: 121
Is it possible to store sub sections of my web.config into external config files?
Currently i simply got this:
<configuration>
<archiveConfiguration>
<company>
<archives>
<archive name="DocumentPool" type="JU">
<parameter key="ConnectionString" value"......" />
<parameter key="ArchiveName" value="DocPool" />
....
</archive>
<archive name="Bills" type="SU">
<parameter key="ConnectionString" value"......" />
<parameter key="ArchiveName" value="Bills" />
....
</archive>
</archives>
</company>
</archiveConfiguration>
</configuration>
Is there any way to just extract the following to an external config file?
<archives>
<archive name="DocumentPool" type="JU">
<parameter key="ConnectionString" value"......" />
<parameter key="ArchiveName" value="DocPool" />
....
</archive>
<archive name="Bills" type="SU">
<parameter key="ConnectionString" value"......" />
<parameter key="ArchiveName" value="Bills" />
....
</archive>
</archives>
How to reference the external config file to web.config so that the application successfully reads the archives section? I tried adding configSource to archives by referencing to archives.config, but i was completely ignored by the web application. Is there something I am missing?
Upvotes: 0
Views: 103
Reputation: 562
Custom subsections support attribute configSource
, so you can extract them into an external config, by setting to a custom section an attribute configSource, in your case this 'section' is element. Put this in Web.config
:
<archives configSource="archives.config" />
And in the archives.config
you'll have
<archives>
<archive name="DocumentPool" type="JU">
<parameter key="ConnectionString" value"......" />
<parameter key="ArchiveName" value="DocPool" />
....
</archive>
<archive name="Bills" type="SU">
<parameter key="ConnectionString" value"......" />
<parameter key="ArchiveName" value="Bills" />
....
</archive>
I assume that you've already created a subclass of ConfigurationSection and then added a custom section handler to Web.config as in this tutorial.
Upvotes: 1