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

发布于 2024-10-01 12:40:53 字数 416 浏览 0 评论 0原文

我目前在 IIS7 中有 2 个 ASP.NET 3.5 Web 应用程序(我们称它们为 WebParent 和 WebChild)。

WebChild 嵌套在 IIS7 中的 WebParent 列表中,并设置为应用程序(而不仅仅是 WebParent 中的虚拟目录)。目前两者都使用自己的(经典)应用程序池。

WebParent 和 WebChild 在自己的根目录中都有自己完全定义的 web.config 文件。

我曾假设将 WebChild 定义为 IIS 中的“应用程序”,它不会从 WebParent 配置文件继承任何内容。然而,尽管有这种配置,我还是看到与已定义的 web.config 中的各种元素相关的错误(这是正确的,两个配置文件中都有几个项目,但我认为它们应该完全独立于一个)其他)?

任何人都可以澄清为什么会发生这种情况吗?

I currently have 2 x ASP.NET 3.5 web applications in IIS7 (lets call them WebParent and 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.

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

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)?

Can anyone please clarify why this might be occurring?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

罗罗贝儿 2024-10-08 12:40:53

您的问题的确切解决方案将取决于您看到的配置异常消息。但是,这是一个典型问题,通常可以通过使用 inheritInChildApplications 属性。通过将整个 system.web 部分包装在一个 location 元素中,如下所示,您应该能够消除您所描述的问题:

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

使用 IIS 7,您还需要以相同的方式包装 system.WebServer 部分:

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

此解决方案基于我在此处找到了一篇出色的博客文章。

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:

<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:

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

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

煮茶煮酒煮时光 2024-10-08 12:40:53

如果它们重复,您必须首先在子应用程序 web.config 中,然后添加回您想要放置的元素。这是假设您希望有不同的值。如果不这样做,则只需省略该元素即可。连接字符串是一个很好的例子,它可能对所有应用程序都很常见 - 因此您只需要在根目录中指定它。

例子:

    <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>

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.

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>
那片花海 2024-10-08 12:40:53

我认为继承InChildApplications =“ false”对于您仍然想从父级继承部分配置的情况很有用。
如果您想完全停止继承(就像在这种情况下,如果我是正确的),我建议为这 2 个应用程序使用 2 个单独的应用程序池,然后在 applicationHost.config 文件中应用记录不充分的设置正如我在这个问题“条目已经已添加” - 两个独立的应用程序池

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

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

<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" enableConfigurationOverride="false">
    <processModel identityType="NetworkService" />
</add>
许久 2024-10-08 12:40:53

遵循 Scott 的建议,并确保您已右键单击 IIS 中的 WebChild 并选择“转换为应用程序”。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文