By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Multiple config files

P: n/a
I quite like to store variables in the web.config file. However it can make
the web.config messy and make deployment fiddly. Is there any way of have
multiple web.config files - one with the major stuff and one with minor
stuff such as my variables which can differ from development to production.
Or alternatively is there some kind of tool to make the deployment smoother?
Regards, Chris.

Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
>I quite like to store variables in the web.config file. However it can make
>the web.config messy and make deployment fiddly. Is there any way of have
multiple web.config files - one with the major stuff and one with minor
stuff such as my variables which can differ from development to production.
Or alternatively is there some kind of tool to make the deployment smoother?
You can define a "configSource=........" attribute for just about
every section in your web.config, to "externalize" your config
settings to separate files:

<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
...
</pages>
</system.web>
<system.serviceModel>
<bindings configSource="serviceModel_bindings.config"/>
<client configSource="serviceModel_client.config"/>
.......
</system.serviceModel>
<connectionStrings configSource="connectionStrings.config" />
........
</configuration>

Those external config files now simply contain the section that you
would normally have directly in your web.config, e.g.

connectionStrings.config:

<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="default" connectionString="........"/>
</connectionStrings>
That alone can make your web.config a lot more readable right there -
and it's totally built in, no extra custom code needed - nada.

Hope this helps.
Marc
Jun 27 '08 #2

P: n/a
I'll have a look at that. It looks like exactly what I'm looking for.
Cheers.

"Marc Scheuner" <no*****@for.mewrote in message
news:gn********************************@4ax.com...
I quite like to store variables in the web.config file. However it can
make
the web.config messy and make deployment fiddly. Is there any way of have
multiple web.config files - one with the major stuff and one with minor
stuff such as my variables which can differ from development to
production.
Or alternatively is there some kind of tool to make the deployment
smoother?

You can define a "configSource=........" attribute for just about
every section in your web.config, to "externalize" your config
settings to separate files:

<?xml version="1.0"?>
<configuration>
<system.web>
<pages>
...
</pages>
</system.web>
<system.serviceModel>
<bindings configSource="serviceModel_bindings.config"/>
<client configSource="serviceModel_client.config"/>
.......
</system.serviceModel>
<connectionStrings configSource="connectionStrings.config" />
.......
</configuration>

Those external config files now simply contain the section that you
would normally have directly in your web.config, e.g.

connectionStrings.config:

<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="default" connectionString="........"/>
</connectionStrings>
That alone can make your web.config a lot more readable right there -
and it's totally built in, no extra custom code needed - nada.

Hope this helps.
Marc
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.