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

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
 
J

Jerry III

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
 
S

Shrinivas Joshi

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
 
J

Jerry III

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
 
J

Jerry III

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top