views:

1564

answers:

2

I want to prevent the parent config in our IIS 7 app from pushing down the following section to any sub web.configs in any applications under the parent application.

 <configSections>
  <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
   <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
     <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
     <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
     <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
     <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
    </sectionGroup>
   </sectionGroup>
  </sectionGroup>
 </configSections>

The reason I need to remove that section is because the sub application doesn't need this or even use it. So when the parent passes it down and I try to run that sub app, I get the following during runtime:

Unable to cast object of type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection' to type 'System.Web.Configuration.ScriptingScriptResourceHandlerSection'

I see no way to prevent the configSections from being applied downward to child application web.configs. You cannot wrap it with <location> around this particular section and adding a <clear/> only causes another error message which is:

The configuration section 'appSettings' cannot be read because it is missing a section declaration
A: 

I believe your runtime error is being caused by something else... like an assembly conflict of some kind, or just a missing assembly. The web.config snippet you posted exists almost verbatim in several projects of mine that I've inherited and works fine with sub apps. However they reference the old 1.0 versions.

The error message doesn't even make sense... "cannot cast type XYZ to type XYZ." Really? You can't? But they're the same type! :|

Bryan
yea I needed to install ASP.NET 1.0 AJAX
CoffeeAddict
A: 

Further to the advice, you can stop child applications from inheriting by adding this to the root web.config

<location path="." inheritInChildApplications="false">
...
</location>

As documented here.

Paul