title: ASP.NET - Unity - Read configuration section from external configuration file
body: <p>I want to integrate Unity in my app and I want it to use an external config file</p>
  
  <p>The Unity initialization code is</p>
  
  <pre><code>var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = "unity.config" };
  System.Configuration.Configuration configuration =
  ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
  
  // *** problem starts here ***
  var unitySection = (UnityConfigurationSection)configuration.GetSection("unity");
  var container = new UnityContainer().LoadConfiguration(unitySection);
  </code></pre>
  
  <p>Also I have external config file for unity, named "unity.config" with the following content</p>
  
  <pre><code>&lt;unity xmlns="http://schemas.microsoft.com/practices/2010/unity"&gt;
    &lt;alias alias="IEmailConfigurator" type="Server.Common.Interfaces.IEmailConfigurator, Server.Common" /&gt;
    &lt;alias alias="EmailConfigurator" type="Server.Common.EmailConfigurator, Server.Common" /&gt;
  
    &lt;namespace name="Server.Common.Interfaces" /&gt;
    &lt;namespace name="Server.Common" /&gt;
  
    &lt;container&gt;
      &lt;register type="IEmailConfigurator" mapTo="EmailConfigurator" /&gt;
    &lt;/container&gt;
  &lt;/unity&gt;  
  </code></pre>
  
  <p>The problem is, in the line where I want to load unitySection, GetSection() returns null.</p>
  
  <p>What could be the problem?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>I added </p>
  
  <pre><code>&lt;configuration&gt;
      &lt;configSections&gt;
          &lt;section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/&gt;
          &lt;/configSections&gt;
  </code></pre>
  
  <p>However, now when I trace through code, in line </p>
  
  <pre><code>System.Configuration.Configuration configuration = //...
  </code></pre>
  
  <p>The configuration variable in initialized that FilePath property is C:\Program Files (x86)\IIS Express\unity.config, and not my own unity.config file</p>
  
  <p>Any idea how to reference the config file from web folder?</p>
  
  <p>Thank you. </p>