The configSource file 'mycustom.config' is also used in a parent, this is not allowed

5.9k Views Asked by At

If you were developed ASP.NET web site in VS2010. (or before VS2015)

And your site is using Virtual Path, for example "http://localhost:12345/myvirpath"

And you have the customize config file by using configSource in Web.config like this:

<configuration>
    <configSections>
        <section name="MyConfig" type="mydomain.MyConfig_Model, mydomain" />
    </configSections>
    <ConfigRoot configSource="mycustom.config" />
    ...
</configuration>

You can test well in development, and you can run your site in the virtual path under the Production IIS smoothly.

Everything works well.


But when you open your solution in VS2015.

Since VS2015 is no longer provide the "ASP.NET Development Server".

You have to use the IISEXPRESS to develop and test your web site.

But when you use the IISEXPRESS, and make the "Project URL" as "http://localhost:12345/myvirpath" in web project properties.

Press "F5", you will get the Error Message:

The configSource file 'mycustom.config' is also used in a parent, this is not allowed.


The reason is that the IISEXPRESS will create 2 sites, "http://localhost:12345/" and "http://localhost:12345/myvirpath"

Both sites will point to the same Physical Path, and this is not allowed.

So there will have that error message.


I've googled this problem many days, and I got a final way to solve this problem, and share it here.

The Solution is:

  1. Open your solution in VS2015.

  2. Make the Project URL is "http://localhost:12345/myvirpath" in your web project properties.

  3. The checkbox of "Override the application root URL" is nonnecessary.

  4. Open your IISEXPRESS config at : "$(solutionDir).vs\config\applicationhost.config", in the <sites> section, you will find the both path "/" and "/myvirpath" are using the same Physical Path.

    <site name="MyWeb.Web-Site" id="2">
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="D:\MyWeb\MyWeb.Web" />
        </application>
        <application path="/myvirpath" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="D:\MyWeb\MyWeb.Web" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation="*:55923:localhost" />
        </bindings>
    </site>
    
  5. Now change the physical path of "/" to another path like this:

    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
    </application>
    
  6. Save it. And now you can use "F5" to execute your web project with no more error message.

0

There are 0 best solutions below