Web.config User Specific appSettings
Mar 20, 2012
1 minute read

On an MVC.NET project at work, we came across the need to be able to override the web.config’s appSettings uniquely on each of our local environments. Turns out there’s a very easy way to do just that inside the web.config file.

Just add the file attribute to the node in your web.config, and add a local.config file to the project root.

<!-- WEB.CONFIG -->
  <appSettings file="local.config">
<?xml version="1.0" encoding="utf-8"?>
	<add key="MySQLConnectionString" value="..." />

Now when your app loads, it will check to see if there’s a local.config file relative to the web.config file. If there is a file, then it overrides any web.config settings it finds duplicates for in the local.config. If the local.config file does not exist, then it is ignored.

Pro tip: Keep local.config out of your code repo and boom! Easily manageable local dev environment settings.

See Also: