views:

221

answers:

3

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?

Thanks in advance!

A: 

You define it again in order to change the behavior of the website.

Suppose you are running several different websites and you want them to be configured differently for a specific section. This would be why they exist in web.config.

Oded
A: 

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
Mehdi Golchin
Ok, thanks that's good to know but I was also wondering what exactly those things do. For example, I know that if I remove something like: <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>Then I will not be able to access any of the classes in System.Web.Extensions in my website. What happens if I remove those config sections from my web.config (and assume they are not in the machine.config either)
Trajanus
@Trajanus, sorry for delay. As you said there are some new configuration sections such as `System.Web.Extensions` that aren't defined in the `machine.config`. These sections are related to ASP.NET AJAX services. Thus, If you remove their definition, you can not use them. If you don't need them, remove this section.
Mehdi Golchin
A: 

All .NET Framework applications inherit basic configuration settings and defaults from a file named systemroot\Microsoft .NET\Framework\versionNumber\CONFIG\Machine.config. The Machine.config file is used for server-wide configuration settings. Some of these settings cannot be overridden in configuration files that are lower down in the hierarchy.

The .NET client applications (console and Windows applications) use configuration files named ApplicationName.config to override inherited settings. The ASP.NET applications use configuration files named Web.config to override inherited settings.

The root of the ASP.NET configuration hierarchy is a file referred to as the root Web.config file, and it is located in the same directory as the Machine.config file. The root Web.config file inherits all of the settings in the Machine.config file. The root Web.config file includes settings that apply to all of the ASP.NET applications that run a specific version of the .NET Framework. Because each ASP.NET application inherits default configuration settings from the root Web.config file, you need to create Web.config files only for settings that override the default settings.

see ASP.NET Configuration File Hierarchy and Inheritance

Iggy