简体   繁体   中英

Web.config in virtual directory is not overriding parent website's Web.config

I've got a website which has a virtual directory that also includes a website, and when I try to launch a page from the virtual directory, I receive an IIS 7.5 error that the name (from the connection string) is already in the collection. This wasn't a problem before I added a domain user as the Identity in the app pool. Does anyone know why this is happening? I was under the impression that sub level application's web.config overrides the parent's by default. And again, this was once working until I added a custom Identity.

The error on the page is "Parser Error Message: The entry 'dbname' has already been added."

Where the dbname is in both connection strings (ie parent and virtual directory). I can't delete one of the connection strings because the virtual directory is only created for test purposes, but in production it runs as its own website.

A sub web.config doesn't override a parent regardless of application. All web.configs will stack up all the way to the root of the primary application. In order for sub-application folder to make use of a connection string key that is already in use it must first be removed or all connection strings must be cleared. If you want this to be a truly stand alone application as a child add this to your connection strings:

<connectionStrings>
    <clear />
    <your connection string>
<connectionStrings>

If you just want to remove the single connection string use this:

<remove key="yourConnectionStringName" />

@u84six,

Today this had happened to me. I had some websites and webservices in the same root website. The root is the default iis website (Default Web Site) and i think it was pointing to C:\\Inetpub\\wwwroot. Its a development environment.

After i read this answer , i found out that one of my webservices was the root website (still not sure what changed it... maybe visual studio after a migration from 2010 to 2012). That webservice was using the connectionString in conflict. I change the path back to C:\\Inetpub\\wwwroot\\ and everything went to normal.

Maybe something similar happened to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM