title: How to define web.config local variables
body: <p>I have a web application in C# with .NET Framework 4.0 and I'm trying to find a way to define a variable in Web.Config that can be referenced elsewhere within the Web.Config.</p>
  
  <p>I want something like this.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LocalWebConfigVars&gt;
      &lt;add key="Var1" value="ServerName1"/&gt;
      &lt;add key="Var2" value="DatabaseName1"/&gt;
  &lt;/LocalWebConfigVars&gt;
  &lt;configuration&gt;
      &lt;connectionStrings&gt;
          &lt;add name="AppConnectionString" connectionString="DATA SOURCE=@Var2 ServerName=@Var1"/&gt;
          &lt;add name="OtherStuff" value="@Var1"/&gt;
  etc...
  </code></pre>
  
  <p>Currently I have to keep 3 or 4 hard-coded values (some embedded others just the value) updated to the same thing and would like to make it easier to keep in sync. </p>
  
  <p>Is this possible?</p>
  
  <p>Thanks.</p>
  
  <p>Edit:</p>
  
  <p>Just some background. The reason this is becoming problematic is that we define the apps database instance (among other instance specific setting) in the web.config. We have multiple database instances in our test and production environments and if I need to switch to a different one them while testing something and miss one of the hand full of references I get some strange results. I'm trying to avoid this by defining it once and referencing it everywhere else.</p>