简体   繁体   English

虚拟目录中的Web.config不会覆盖父网站的Web.config

[英]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. 我有一个网站,其中有一个虚拟目录,其中还包含一个网站,当我尝试从虚拟目录启动一个页面时,我收到一个IIS 7.5错误,该名称(来自连接字符串)已经在该集合中。 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. 我的印象是子级应用程序的web.config默认覆盖了父级。 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." 页面上的错误是“分析器错误消息:已添加条目'dbname'。”

Where the dbname is in both connection strings (ie parent and virtual directory). 其中dbname位于两个连接字符串中(即父目录和虚拟目录)。 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. 无论应用程序如何,子web.config都不会覆盖父级。 All web.configs will stack up all the way to the root of the primary application. 所有web.configs都会一直堆叠到主应用程序的根目录。 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, @ 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. 根是默认的iis网站(默认网站),我认为它指向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). 在我读完这个答案之后 ,我发现我的一个网络服务是根网站(仍不确定是什么改变了它......也许是从2010年到2012年迁移后的视觉工作室)。 That webservice was using the connectionString in conflict. 该web服务正在使用冲突中的connectionString。 I change the path back to C:\\Inetpub\\wwwroot\\ and everything went to normal. 我将路径更改回C:\\ Inetpub \\ wwwroot \\,一切都恢复正常。

Maybe something similar happened to you. 也许类似的事情发生在你身上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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