views:

782

answers:

4

Is it possible to configure an IIS site to read ASP.Net settings from a site OTHER than web.config?

We'd like to have three config files in our codebase -- web-dev.config, web-test.config, and web-prod.config. Each IIS instance would be configured to read from their specific file. This way we have version control them all next to each other (and one-click deploy the entire site) but know that each IIS instance will read the settings specific to itself.

I've found in IIS where it shows where the web.config is, but I can't see how to change the location.

A: 

At my company we just have our deployment tool set to copy the appropriate file to web.config depending on what kind of deployment we're doing.

RossFabricant
A: 

I believe it has to be named web.config.

You are facing a common problem.

One solution that I have used that worked really well in a large organization was to set environment variables on the web servers. Such as DEV, QA, UAT, PROD. Then, in code, you can query the environment variable to see which machine you are on, and then choose the values of appSettings accordingly. For example, you could have a database connection string named DEVconnection, and another named UATconnection. If your code determines from the environment variable that you are on UAT, then it would use UATconnection.

This does assume that you have the ability to set environment variables on the web server. In this instance, the admins running the servers were the ones who suggested this solution.

What was sweet about this was that there was ever only one version of web.config.

DOK
Your plan is a good, and one we've thought of before. However, we use several commercial components that are hard-coded to certain appSettings keys that we cannot change.
Deane
Aaargh! I feel your pain.
DOK
+1  A: 

The best solution right now is to use different configs for development and production. This however will change with .net 4 and VS 2010 which they have added Web.Debug.config, Web.Release.config, Web.Staging.config and Web.Testing.config which will then publish the config you need in relation to the environment.

+2  A: 

I use the configSource property to specify an external config file for sections that need different values for dev and production.

<connectionStrings configSource="Config\ConnDev.config"/>

Then you only have to change one setting (manually or with a tool) to switch from Dev to Production configs.

Jimmie R. Houts