Environment specific web.config using appSettings file property

1 minute read

As most companies do, you would have different environments such as INT (intergration), Staging, and Live servers. Web.config is really handy, but you cannot put environment specific settings there, because the same file is deployed across all environments.

This troubleed me and my company (which is Totaljobs) for a while and I came across this file property.

Put the file property like this.

[sourcecode language='xml']


MSDN says,

Optional String attribute.

Specifies a relative path to an external file that contains custom application configuration settings. The specified file contains the same kind of settings that are specified in the appSettings add, clear, and remove attributes and uses the same key/value pair format as those elements.

The path that is specified is relative to the local configuration file. The runtime ignores the attribute, if the specified file cannot be found.

Because any changes to the Web.config file cause the application to restart, using a separate file allows users to modify values that are in the appSettings section without causing the application to restart. The contents of the separate file are merged with the appSettings section in the Web.config file. This functionality is limited to the appSettings attribute.

Yet you can still use an absolute path. We use a path like "c:\program files\company\config\evweb.config"

Ah, the content of evweb.config is like this.

[sourcecode language='xml']

Hope this helps.