What is the purpose of configSections?

Trajanus picture Trajanus · Jan 15, 2010 · Viewed 7.6k times · Source

I've done a little research and ran across this: http://msdn.microsoft.com/en-us/library/ms228245.aspx

So if I'm understanding that correctly, ultimately what this is doing is including some .dlls for use within the project, much like:

<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

And I'm guessing the difference is that if you do it the configSections way you can set some parameters by creating the 'name' later in the webconfig (or other config) as an xml element. Is this correct, or am I missing something?

Also, I noticed that I can remove a configSections from a website's web.config and it will run fine, specifically the following configSections:

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

I was reading somewhere that you could do this and have it still run because configSections was also defined by default in the machine.config. So why define it again in a website's web.config? I assume to override the machine.config with some custom settings? Is there some way for me to determine what the default contents of a machine.config file is?

Answer

Mehdi Golchin picture Mehdi Golchin · Jan 15, 2010

You are right. ASP.NET configuration sections are defined within machine.config. It's an hierarchy which each configuration file overrides its parent. You can find the machine.config and root web.config file under the following directory.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG