Multiple config files

  • Thread starter Thread starter Robert Cramer
  • Start date Start date
R

Robert Cramer

Option 1: Create your own XML files. Name them whatever you like - even with
a .config extension (as long as the rest of the name doesn't conflict with
the convention expected by .NET, which is ApplicationName.config - the name
that Web.config takes after compilation). Then read your XML files as plain
ole' XML documents, parsing out your configuration values however you like.

Option 2: Store your config values in a database and retrieve them as
necessary and/or during Application_Start.

Option 3: Have multiple Web.config files. In order to do this, the files
must exist at different levels in, or relative to, the application. Config
files can or do exist at the server level, the site level (in the site
root), or in sub folders. If in sub folders, then the settings apply to only
the pages etc within the respective sub folders. But as far as having
multiple config files at the same "level" (e.g., in the site root), I
believe this is not possible, unless you go witth reading them as plain ole'
XML documents and not reading them via the .NET configuration system.

-HTH
 
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
 
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.
 
Back
Top