How can I prevent applicationSettings in the web.config from being inherited?

无人久伴 提交于 2019-12-11 04:08:28

问题


I have an applicationSettings section in my web.config in my ASP.NET 2.0 web application. This works perfectly for storing values and being able to access them as strongly-typed values.

Here is a snippet of my web.config:

<configuration>
 ... 
 <applicationSettings>
     <MyWebsite.Properties.Settings>
        <setting name="ExcludedItemNumbers" serializeAs="Xml">
           <value>
              <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                 <string>123</string>
                 <string>124</string>
              </ArrayOfString>
           </value>
        </setting>
     </MyWebsite.Properties.Settings>
  </applicationSettings>
</configuration>

However, I have another Virtual Directory below this on the IIS server (which by default inherits this web.config). After adding the applicationSettings to this web.config, the child Virtual Directory throws a runtime error complaining of a bad web.config (I'm assuming because MyWebsite.Properties.Settings is not a valid type in the child site).

How can I keep the strongly-typed access to my settings in this site and not break the site that is inheriting this web.config? I have tried doing the location tag around the applicationSettings tag, but that gives a runtime error on this site.


回答1:


You can add the clear element to your child web.config file.

<appSettings file="">
      <settings>
         <clear />
      </settings>
   </appSettings>



回答2:


You can also use the remove element:

<appSettings>
      <settings>
         <remove key="someKey" />
         <add key="someKey" value="a new value" />
      </settings>
</appSettings>


来源:https://stackoverflow.com/questions/884515/how-can-i-prevent-applicationsettings-in-the-web-config-from-being-inherited

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!