asp.net - 如何停止 Web.Config 中 <configSections> 的继承

标签 asp.net web-config

您根本无法使用<location path="." inheritInChildApplications="false">在 web.config 的某些部分,以便告诉它忽略某些部分的继承(您会收到诸如“未声明 inheritInChildApplications 属性”之类的错误,如果您尝试将其放入不支持的部分,则会出现第四个错误)。

例如,您不能在 <configSections> 之前或内部使用它。例如,您可以包装您的 <system.web>位置标签中的标签,但我需要停止 <configSections> 中任何内容的继承我看不出有什么办法可以做到这一点。

我的子应用程序继承了树中 IIS 7 中父应用程序 Web 配置的一些相同配置设置。我看不出有什么办法可以写 <clear/>要么在 configSecion 标记中,因为如果您尝试将其添加到那里,它是无效标记。

你如何告诉它忽略该部分?

最佳答案

这个同样的问题在 SO 以及许多其他论坛上被多次问到,答案或多或少是相同的,不,你不能使用 location/clear/remove 来配置部分。

微软甚至在他们的帖子中回复如下。

Posted by Microsoft on 7/23/2009 at 5:40 PM

 <clear /> and <remove />

were never implemented for configSections and sectionGroups because of the difficulty involved attempting to merge different definitions of the same section-handlers and section groups.

We considered adding this type of functionality for the VS 2010 release, but we decided against it for two reasons.

The first one being the additional complexity it brings, in large part because section handlers and section groups are used to bootstrap the configuration system. As a result allowing for merge semantics in the middle of bootstrapping the configuration system is a non-trivial problem to solve.

The second reason is that usually section handlers and section group definitions are made in two distinct places - an initial set of registrations up in the root configuration files, and then an additive set of registrations in application level web.config. That doesn't mean a scenario where a developer wants to modify handler definitions isn't valid - its just a low likelihood scenario. Thank you for taking the time though to submit your suggestion via Connect!

<小时/>

查看这个 SO 线程,其中简单的状态避免使用冲突的节组。

但是,Nairman 建议遵循以下步骤:

I'm not sure that you can have the same section defined differently in a sub-folder; you could make that sub-folder a stand-alone virtual application, in which case it wouldn't inherit any of the settings from the parent; in this scenario, it would also execute in its own app pool; if you don't have InProc dependencies, that's an option as well

How to prevent inheritance for web.config file for "configSections"?

关于asp.net - 如何停止 Web.Config 中 <configSections> 的继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1572326/

相关文章:

javascript - 使用 SweetAlert2 替换 ASP.Net 按钮上的 "return confirm()"

c# - 带有帐户的新 Web 应用程序

c# - 将值传递给 ASP.NET 中的 javascript

asp.net - IIS 忽略 system.webServer staticContent 部分

c# - 尝试替换 connectionStrings 元素以在 Visual Studio Team Services 中进行持续部署

c# - 未将对象引用设置为实例

c# - 无法从 RowIndex 获取 Gridview 行数据

html - @{#if DEBUG} 不起作用

c# - 大数据量的 Web API 中的 502 错误

asp.net - 将我的 Web.Config 应用程序设置存储在单独的文件中时,是否总是需要 IIsreset?