C# 如何停止 web.config 继承

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1049573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:59:39  来源:igfitidea点击:

How do I stop web.config inheritance

c#asp.netweb-config

提问by danswain

Ok

好的

I have a Asp .net 3.5 Website in IIS6 on Windows Server 2003 (32bit).

我在 Windows Server 2003(32 位)上的 IIS6 中有一个 Asp .net 3.5 网站。

with a Asp.Net 1.1 WebApplication in a sub virtual directory. (this is set to use the older 1.1 .net runtime and is configured with it's own App Pool. So for all intents and purposes is completely seperate.

在子虚拟目录中使用 Asp.Net 1.1 WebApplication。(这被设置为使用较旧的 1.1 .net 运行时并配置了它自己的应用程序池。因此对于所有意图和目的是完全独立的。

Except it keeps on inheriting the root website's .net 3.5 web.config.

除了它继续继承根网站的 .net 3.5 web.config。

I've tried adding

我试过添加

<location path="." inheritInChildApplications="false">

to the root websites web.config but it doesn't seem to work.

到根网站 web.config 但它似乎不起作用。

Strangely the error is actually

奇怪的是,错误实际上是

<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

which is being reported from the .net 1.1 runtime with the website path WEBSITE/OLD_WEBAPP but it's moaning about the webSite (as in the .net 3.5 one's) web.config and how it doesn't understand the type attribute on the sectionGroup tag.

这是从网站路径 WEBSITE/OLD_WEBAPP 的 .net 1.1 运行时报告的,但它正在抱怨网站(如在 .net 3.5 中的)web.config 以及它如何不理解 sectionGroup 标记上的类型属性。

What am I doing wrong? Please tell me it's something obvious. Thanks

我究竟做错了什么?请告诉我这是显而易见的事情。谢谢

采纳答案by danswain

Just to let everyone know, I've found an answer that serves my purposes for now.

只是为了让大家知道,我已经找到了一个适合我现在目的的答案。

I ended up putting all the configuration in the .net 2.0 global web.config

我最终将所有配置放在 .net 2.0 全局 web.config 中

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG

I got this suggestion from this comment on connect.microsoft.com

我从connect.microsoft.com 上的这条评论中得到了这个建议

The configuration systems for both ASP.NET 1.1 and 2.0 are hierarchichal. As a result if a different framework version is a child of the root website (which is usually inetpub\wwwroot), then the configuration system in the child will attempt to merge the configuration from the root website. This behavior is by design since both the 1.1 and 2.0 configuration systems walk up the physical directory structure looking for parent web.configs.

A simple workaround is to move the common 2.0 configuration information to the root web.config file for the 2.0 framework. The root web.config is located at: C:\windows\Microsoft.NET\Framework\v2.0.50727\CONFIG. With this approach all of your 2.0 applications will pick up the common sections while 1.1 applications won't see the sections.

Thank you for submitting this issue. Hope the above information is useful for you.

Posted by Microsoft on 22/02/2008 at 17:35

ASP.NET 1.1 和 2.0 的配置系统都是分层的。因此,如果不同的框架版本是根网站(通常是 inetpub\wwwroot)的子级,则子级中的配置系统将尝试从根网站合并配置。这种行为是设计使然,因为 1.1 和 2.0 配置系统都会在物理目录结构中查找父 web.configs。

一个简单的解决方法是将常见的 2.0 配置信息移动到 2.0 框架的根 web.config 文件中。根 web.config 位于:C:\windows\Microsoft.NET\Framework\v2.0.50727\CONFIG。使用这种方法,您的所有 2.0 应用程序都会选择公共部分,而 1.1 应用程序不会看到这些部分。

感谢您提交此问题。希望以上信息对您有用。

由 Microsoft 于 22/02/2008 于 17:35 发表

Seems to work for me, though it's not quite as elegant as if it had been a .net 2.0 application. Hope this helps someone else.

似乎对我有用,尽管它不像 .net 2.0 应用程序那样优雅。希望这对其他人有帮助。

Dan

回答by Ian Oxley

Most of the sections in Web.config can have a tag added to them - it might be worth adding this to the affected sections to see if it solves your inheritance probem (see Is it possible to completely negate a "higher" web.config in a subfolder?for some caveats to watch out for).

Web.config 中的大多数部分都可以添加一个标记 - 可能值得将其添加到受影响的部分以查看它是否解决了您的继承问题(请参阅是否有可能完全否定“更高”的 web.config子文件夹?要注意一些注意事项)。

回答by Kyle B.

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