嵌套的ASP。NET“应用程序”在IIS中继承父配置值吗?

时间:2022-12-02 11:26:30

I currently have 2 x ASP.NET 3.5 web applications in IIS7 (lets call them WebParent and WebChild).

我现在有2xasp。在IIS7中,NET 3.5 web应用程序(我们称之为WebParent和WebChild)。

WebChild is nested within the WebParent listing in IIS7 and is set up as an application (rather than just a virtual directory within WebParent). Both currently use their own (Classic) application pool.

WebChild嵌套在IIS7的WebParent列表中,并作为一个应用程序(而不仅仅是WebParent中的虚拟目录)设置。它们现在都使用自己的(Classic)应用程序池。

Both WebParent and WebChild have their own fully defined web.config files in their own root directories.

WebParent和WebChild都有自己的完全定义的web。配置文件在它们自己的根目录。

I had assumed that seeing as WebChild is defined as an 'Application' within IIS, that it would not inherit anything from the WebParent configuration file. However, despite this configuration, I am seeing errors related to various elements within the web.config already being defined (which is correct, there are a couple items that are in both config files, but I thought they should be treated completely independently from one another)?

我曾经假设,将WebChild定义为IIS中的“应用程序”,它将不会从WebParent配置文件继承任何东西。然而,尽管有这样的配置,我还是看到了web中与各种元素相关的错误。已经定义了配置(这是正确的,在两个配置文件中都有一些条目,但是我认为它们应该完全独立地处理)?

Can anyone please clarify why this might be occurring?

有人能解释一下为什么会出现这种情况吗?

4 个解决方案

#1


14  

If they are repeated, you'll have to <remove/> then in the child application web.config first, then add back the element you'd like it it's place. This is assuming that you'd like to have a different value. If you don't, then just omit the element. A connection string would be a good example of something that is likely common for all applications - so you only need to specify it in the root.

如果重复,则必须在子应用程序web中 。先配置好配置,然后再添加你喜欢的元素。这是假设你想要一个不同的值。如果没有,就省略元素。连接字符串将是所有应用程序可能通用的一个很好的例子,所以您只需要在根中指定它。

Example:

例子:

    <siteMap defaultProvider="AdminSiteMapProvider" enabled="true">
      <providers>
        <remove name="AdminSiteMapProvider"/>
        <add name="AdminSiteMapProvider" description="Admin SiteMap provider" type="System.Web.XmlSiteMapProvider" siteMapFile="~/App_Data/admin.sitemap" securityTrimmingEnabled="true" />
      </providers>
    </siteMap>

#2


56  

The exact solution to your problem will depend on what configuration exception message you are seeing. However, this is a typical problem that can often be solved through use of the inheritInChildApplications attribute on the location element in the web.config for "WebParent". By wrapping the entire system.web section in a location element as follows, you should be able to eliminate the problem you described:

对您的问题的精确解决将取决于您所看到的配置异常消息。然而,这是一个典型的问题,通常可以通过在web的location元素上使用继承子应用程序属性来解决。配置为“WebParent”。通过包装整个系统。在一个位置元素的web部分如下,您应该能够消除您描述的问题:

<location path="." inheritInChildApplications="false">
  <system.web>
    <!-- ... -->
  </system.web>
</location>

With IIS 7, you will also want to wrap the system.WebServer section the same way:

使用IIS 7,您还需要封装系统。WebServer部分相同:

<location path="." inheritInChildApplications="false"> 
  <system.webServer>
    <!-- ... -->
  </system.webServer>
</location>

This solution is based on an excellent blog article that I found here.

这个解决方案基于我在这里找到的一篇优秀的博客文章。

#3


2  

I think the inheritInChildApplications="false" is good for cases where you still want to inherit some part of the configuration from the parent. In cases where you want to completely stop inheritance (as in this case if I'm correct), I'd suggest to use 2 separate application pools for the 2 apps and then apply a not very well documented setting in the applicationHost.config file as I explained in this question “Entry has already been added” - Two Separate App Pools

我认为继承子应用程序=“false”对于您仍然希望继承父类的部分配置的情况很好。在需要完全停止继承的情况下(如果我是正确的),我建议为两个应用程序使用两个单独的应用程序池,然后在applicationHost中应用一个没有很好的文档设置。我在这个问题中解释的配置文件“条目已经添加了”——两个单独的应用程序池。

<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
    <processModel identityType="NetworkService" />
</add>

#4


-1  

Follow Scott's advise and also ensure that you have right clicked WebChild in IIS and selected Convert to Application.

遵循Scott的建议,并确保您在IIS中正确地点击了WebChild,并选择了Convert to Application。

#1


14  

If they are repeated, you'll have to <remove/> then in the child application web.config first, then add back the element you'd like it it's place. This is assuming that you'd like to have a different value. If you don't, then just omit the element. A connection string would be a good example of something that is likely common for all applications - so you only need to specify it in the root.

如果重复,则必须在子应用程序web中 。先配置好配置,然后再添加你喜欢的元素。这是假设你想要一个不同的值。如果没有,就省略元素。连接字符串将是所有应用程序可能通用的一个很好的例子,所以您只需要在根中指定它。

Example:

例子:

    <siteMap defaultProvider="AdminSiteMapProvider" enabled="true">
      <providers>
        <remove name="AdminSiteMapProvider"/>
        <add name="AdminSiteMapProvider" description="Admin SiteMap provider" type="System.Web.XmlSiteMapProvider" siteMapFile="~/App_Data/admin.sitemap" securityTrimmingEnabled="true" />
      </providers>
    </siteMap>

#2


56  

The exact solution to your problem will depend on what configuration exception message you are seeing. However, this is a typical problem that can often be solved through use of the inheritInChildApplications attribute on the location element in the web.config for "WebParent". By wrapping the entire system.web section in a location element as follows, you should be able to eliminate the problem you described:

对您的问题的精确解决将取决于您所看到的配置异常消息。然而,这是一个典型的问题,通常可以通过在web的location元素上使用继承子应用程序属性来解决。配置为“WebParent”。通过包装整个系统。在一个位置元素的web部分如下,您应该能够消除您描述的问题:

<location path="." inheritInChildApplications="false">
  <system.web>
    <!-- ... -->
  </system.web>
</location>

With IIS 7, you will also want to wrap the system.WebServer section the same way:

使用IIS 7,您还需要封装系统。WebServer部分相同:

<location path="." inheritInChildApplications="false"> 
  <system.webServer>
    <!-- ... -->
  </system.webServer>
</location>

This solution is based on an excellent blog article that I found here.

这个解决方案基于我在这里找到的一篇优秀的博客文章。

#3


2  

I think the inheritInChildApplications="false" is good for cases where you still want to inherit some part of the configuration from the parent. In cases where you want to completely stop inheritance (as in this case if I'm correct), I'd suggest to use 2 separate application pools for the 2 apps and then apply a not very well documented setting in the applicationHost.config file as I explained in this question “Entry has already been added” - Two Separate App Pools

我认为继承子应用程序=“false”对于您仍然希望继承父类的部分配置的情况很好。在需要完全停止继承的情况下(如果我是正确的),我建议为两个应用程序使用两个单独的应用程序池,然后在applicationHost中应用一个没有很好的文档设置。我在这个问题中解释的配置文件“条目已经添加了”——两个单独的应用程序池。

<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
    <processModel identityType="NetworkService" />
</add>

#4


-1  

Follow Scott's advise and also ensure that you have right clicked WebChild in IIS and selected Convert to Application.

遵循Scott的建议,并确保您在IIS中正确地点击了WebChild,并选择了Convert to Application。