1

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 
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471

2 Answers2

2

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
  • 1,188
  • 1
  • 11
  • 21
  • I know this wasn't the accepted answer, but this was exactly what I was looking for and fits the stated question (even thought it sounds like the asker was having a different problem). – Zack Jan 01 '11 at 00:29
1

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
  • 8,748
  • 7
  • 41
  • 62