Preventing application configuration inheritance in ASP.NET

It’s an extremely common problem: you create a virtual directory to house a supporting application, but accessing it throws an exception because it is trying to initialise the httpmodules/httphanders from the root application. Attempting to them doesn’t work because the clear happens after they are added, which means they need to exist in order to remove them.

Thankfully there is a solution. Introduced in .NET 2.0, the SectionInformation.InheritInChildApplications property, when set to false, stops the runtime from even attempting to load anything from that location when in a child application (like a virtual directory).

Now, as SectionInformation maps directly to the configuration element, it means the offending sections will need to be wrapped in a . When referring to the root application, you can either leave out the path attribute or assign it to “.”

What is strange is that the inheritInChildApplications attribute is not document on the location Element MSDN page, or is it in the schema that is included in VS.NET. This would explain why its existence is not common knowledge

For clarity, I have modified the default web.config template to include the change


      <!--
            The  section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->

      <!--
            The  section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        -->
Advertisement
This entry was posted in .NET 2.0, ASP.NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s