Is it possible to distribute web.config data into multiple files?

  • Thread starter Thread starter Shrinivas
  • Start date Start date
S

Shrinivas

Hi,

Let us say my web.config is keep growing and I want to break the data
logically and still use web.config methods to retrieve the data.
e.g.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Group Name">
<section name="Section name"> </section>
</sectionGroup>
</configSections>
<system.web>
</system.web>
</configuration>


Is it possible to keep the <sectionGroup name="Group Name"> or
<section name="Section name"> in seperate file?

Thanks In advance,
~SJ
 
Dino,

what does your link about appSettings have to do with this? The question was
if it's possible to do includes in web.config, resulting in the file being
split into multiple config files...

Jerry
 
Thanks for your reply.

But I was expected on sectionGroup not on appSettings

**********
<configsections>
<sectionGroup name="Group name">
<section name="Section name"> </section>
</sectiongroup>
</configsections>
*********

Thanks In Advance,
Shrinivas Joshi
 
Ok, now you're just changing your question. If you want to add your own
sections (but still keep everything in one web.config file) you just have to
declare those sections before you use them. Like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="data"
type="System.Configuration.NameValueFileSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<!-- Your regular web.config stuff -->
<data>
<add key="ConnectionString" value="Provider=SQLOLEDB; Data
Source=SqlServer;" />
</data>
</configuration>

and retrieve it like this:

((NameValueCollection)ConfigurationSettings.GetConfig("data"))["ConnectionSt
ring"]

For some reason type="System.Configuration.NameValueFileSectionHandler,
System" didn't work, I had to add version, culture and public key token to
the section definition. Also note that there are other section handlers too.

Jerry
 
I think the only way to do that right now is to write your own section
handler (possibly derived from SingleTagSectionHandler so you won't have to
write the code to read the include tag) that would include your other
configuration files.

Jerry
 
Back
Top