如何防止web.config中的applicationSettings被继承? [英] How can I prevent applicationSettings in the web.config from being inherited?

查看:189
本文介绍了如何防止web.config中的applicationSettings被继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP.NET 2.0 Web应用程序中的web.config中有一个applicationSettings部分。这非常适合存储值并能够以强类型值访问它们。

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.

这是我的web.config的片段:

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>

但是,我在IIS服务器上有另一个虚拟目录(默认情况下继承此Web。配置)。将applicationSettings添加到此web.config后,子虚拟目录会引发运行时错误,抱怨错误的web.config(我假设因为MyWebsite.Properties.Settings不是子站点中的有效类型)。

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

如何保持对此站点中我的设置​​的强类型访问,而不是破坏继承此web.config的站点?我试过做位置标记,但在此网站上出现运行时错误。

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.

推荐答案

你可以将 clear元素添加到您的子web.config文件中。

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

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

这篇关于如何防止web.config中的applicationSettings被继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆