c# - 如何防止 "configSections"的 web.config 文件继承?

标签 c# asp.net visual-studio visual-studio-2010

我的父 Web 应用程序配置文件中有以下内容

<configuration>
  <configSections>
    <sectionGroup name="testmodule">
      <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
    </sectionGroup>
  </configSections>
</configuration>

我想防止子文件夹继承这个配置部分我应该放在哪里 <location path="." inheritInChildApplications="false"> , 因为配置部分应该是配置文件的第一个子元素

最佳答案

这已经在 SO 上回答了几次,但我认为是错误的。

文档非常清楚 (1)(2):

The following example shows how to use this attribute in a configuration file to specify that the settings defined in the location element for the root of a Web site should not be inherited by child applications:

The InheritInChildApplications property applies only to location-specific configuration settings.

要回答您的问题,这应该足够了:

<configuration>
...
<sectionGroup name="testmodule">
    <section name="testmodule" type="RewriteModule.RewriteModuleSectionHandler, RewriteModule"/>
</sectionGroup>
...
<location path="." inheritInChildApplications="false">
    <testModule>
    ....
    </testModule>
</location>

(1) - http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.inheritinchildapplications.aspx

(2) - http://msdn.microsoft.com/en-us/library/ms178692.aspx

关于c# - 如何防止 "configSections"的 web.config 文件继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4030891/

相关文章:

c# - 在 .NET Web 应用程序中填充缓存时的线程管理

c# - Asp.Net 尝试获取 ClientID

ios - 在 Visual Studios Xamarin 中调试 IOS 扩展时出错

c# - 无法重载具有类型约束的泛型方法

c# - 无法访问 Newtonsoft.Json.Linq.JProperty 上的子值 - 使用 LinQ 检查 JObject 时发生错误

c# - ASP.Net Dropdownlist ListItem (Enabled=false) 未显示在页面中

c++ - 共享预编译头文件

c# - 如何验证调用堆栈上的参数 "high up"?

c# - 为什么所有立方体的纹理 UV 贴图都发生了变化?

visual-studio - 从 Visual Studio CLI 构建 SSAS 2016