2

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.

Community
  • 1
  • 1
Andy May
  • 4,030
  • 5
  • 34
  • 33
  • 1
    Have you tried having the child virtual directory run in a different application pool? Also have you tried adding a web.config to the child virtual directory? – Jeff May 20 '09 at 23:50
  • The child virtual directory has its own web.config but it DOES run in the same application pool. I will try giving it its own AppPool and post my results. Thanks for the suggestion! – Andy May May 21 '09 at 18:28
  • @JD, a great idea, perhaps it should have been an answer. – C. Ross May 21 '09 at 18:30

2 Answers2

1

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

<appSettings file="">
      <settings>
         <clear />
      </settings>
   </appSettings>
Daniel Pollard
  • 1,230
  • 1
  • 12
  • 11
1

You can also use the remove element:

<appSettings>
      <settings>
         <remove key="someKey" />
         <add key="someKey" value="a new value" />
      </settings>
</appSettings>
cbp
  • 25,252
  • 29
  • 125
  • 205