Iis – The configSource file ‘connections.config’ is also used in a parent, this is not allowed.

asp.netiisiis-7.5web.config

Question:

I face the following situation:

A ASP.NET .NET 4.0 web-application deployed on machine "vmsomething".

The web-application running on IIS 7.5 resides in d:\webs\myapplication on vmsomething.

The application's config files:

connections.config

<?xml version="1.0"?>
<connectionStrings>
  <remove name="server"/>
  <add name="server" connectionString="Data Source=OUR_DB_Server;Initial Catalog=MY_INITIAL_CATALOG;Persist Security Info=False;User Id=OUR_DB_User;Password=OUR_TOP_SECRET_PASSWORD;MultipleActiveResultSets=False;Packet Size=4096;Application Name=&quot;MyApplication&quot;" providerName="System.Data.SqlClient"/>
</connectionStrings>

web.config:

<?xml version="1.0"?>
<configuration>

  <connectionStrings configSource="connections.config"/>

  <system.web>
    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>
    <compilation strict="true" explicit="true">
      <assemblies>
        <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.JScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
    </compilation>
    <authentication mode="Windows"/>
    <pages>
      <namespaces>
        <clear/>
        <add namespace="System"/>
      </namespaces>
    </pages>
    <customErrors mode="Off">
      <error statusCode="404" redirect="~/w8/index.html"/>
    </customErrors>
    <globalization uiCulture="de" culture="de-CH" requestEncoding="UTF-8" responseEncoding="UTF-8"/>
    <httpRuntime maxRequestLength="2048000" executionTimeout="86400"/>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
</configuration>

Then one can access the application on two ways:
Method One: http://vmsomething.com
Method Two: http://vmsomething.com/my_application_virtdir
(without .com, can't add local links)

Now I can open the application on http://vmsomething.com just fine.
If I try to open the application on http://vmsomething.com/my_application_virtdir , i get this error:

Config Error

I am not the admin of the server, and I don't know how he configured it.
Now to my question:

  • What causes this error ?
  • How to fix it ?

Best Answer

The reason is that you have two web sites targeted on the same physical folder. And there exists an inheritance in web.config.

http://vmsomething is the parent and http://vmsomething/my_application_virtdir is its child. The child web.config inherits all elements from its parent. And the web.config usually is not designed to work in such scenario. You can get a lot of headaches when other utilities installed from nuget will try to modify your web.config.

If you want to access your website at http://vmsomething/my_application_virtdir then I guess the easiest solution will be to change the physical path for http://vmsomething to something different.

If you want to test how your website works without specifying virtdir you can configure a separate website in IIS (not Default Web Site) and target it to the same physical path. Then you will be able to test both ways of deployment at the same time.