Environment specific web.config using appSettings file property

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.

<appSettings file="relative file name" >

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.

    <add key="key" value="value" />

Hope this helps.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s