When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML
Information:
Advertise
Feedback
Author an Article
Jobs
















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this Page!

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Wednesday, December 12, 2007

Dissecting ASP.NET Version 3.5's Web.config File
By Scott Mitchell


Introduction
In November, Microsoft released the final version of ASP.NET 3.5 and Visual Studio 2008. As discussed in An Overview of ASP.NET 3.5 and Visual Studio 2008, version 3.5 is not a major reworking of the .NET Framework. Rather, it adds new classes and functionality on top of the existing core.

If you've had a chance to check out Visual Studio 2008, you may have noticed that it creates a rather verbose Web.config file with a bevy of configuration elements not found in the more terse Web.config file created by Visual Studio 2005. Likewise, when opening an existing Visual Studio 2005 project in Visual Studio 2008, you are prompted with a dialog box asking if you want to upgrade the website to use .NET Framework version 3.5. If you click Yes, Visual Studio updates the application's Web.config file to include the additional markup.

In this article we will examine each of the additional configuration elements added by Visual Studio 2008 to ASP.NET 3.5 applications. Read on to learn more!

- continued -

A Look at the Default Web.config File Used by Visual Studio 2005
When you create a new ASP.NET web application in Visual Studio 2005, the project's default Web.config file looks something like the following. (I've removed comments for brevity)

<?xml version="1.0"?>
<configuration>
    <appSettings/>
    <connectionStrings/>

    <system.web>
       <compilation debug="false" strict="false" explicit="true" />

       <pages>
            <namespaces>
                <clear />
                <add namespace="System" />
                <add namespace="System.Collections" />
                <add namespace="System.Collections.Specialized" />
                <add namespace="System.Configuration" />
                <add namespace="System.Text" />
                <add namespace="System.Text.RegularExpressions" />
                <add namespace="System.Web" />
                <add namespace="System.Web.Caching" />
                <add namespace="System.Web.SessionState" />
                <add namespace="System.Web.Security" />
                <add namespace="System.Web.Profile" />
                <add namespace="System.Web.UI" />
                <add namespace="System.Web.UI.WebControls" />
                <add namespace="System.Web.UI.WebControls.WebParts" />
                <add namespace="System.Web.UI.HtmlControls" />
            </namespaces>
       </pages>

       <authentication mode="Windows" />
    </system.web>
</configuration>

The <configuration> element is the XML document's root element. The default Web.config created by Visual Studio 2005 adds three child elements to the <configuration> element:

  • <appSettings> - the place for the page developer to specify application-wide constants and other simple, scalar settings.
  • <connectionStrings> - the place to specify database connection strings used by the application.
  • <system.web> - contains configuration settings for the ASP.NET web applicaiton, such as authentication and authorization options, compilation options, custom error page settings, HTTP Handlers and Modules, and so on.
Within the default Web.config file's <system.web> element there are three additional child elements:
  • <compilation> - settings that dictate how ASP.NET pages are compiled
  • <pages> - default settings for all ASP.NET pages within the application. Here, the <pages> element has a child element, <namespaces>, which define those namespaces imported into all ASP.NET pages by default.
  • <authentication> - the authentication model used by the ASP.NET application.
Of course, these six elements are but a few of the many possible elements that may appear in the configuration file. But these are the default ones that are entered by Visual Studio 2005.

Changes to the Default Web.config File in Visual Studio 2008
As discussed in An Overview of ASP.NET 3.5 and Visual Studio 2008, Visual Studio 2008 can be used to create ASP.NET version 2.0, version 3.0, or version 3.5 applications. To specify the version being targeted, right-click on the website project in the Solution Explorer and select Property Pages from the context menu. From the Property Pages, select the Build option in the left column. You can then choose the version to target from the drop-down list on the right.

Specify the ASP.NET version to target.

Visual Studio 2008 automatically updates the application's Web.config file based on the version being targeted.

Similarly, when you open an existing ASP.NET 2.0 application in Visual Studio 2008, you are prompted as to whether you want to upgrade the website to ASP.NET version 3.5.

The Upgrade to Version 3.5 Prompt

If you choose Yes, Visual Studio 2008 targets the application to version 3.5, thereby updating the Web.config file.

The (rather lengthy) default Web.config markup used by Visual Studio 2008 for applications targeted for version 3.5 looks similar to the following. (I've removed comments for brevity) The Web.config file created by Visual Studio 2008 has some portions identical to the one created by Visual Studio 2005. Those portions that are different are are highlighted a light yellow color. When reviewing the differences, keep in mind that ASP.NET version 3.5 is ASP.NET version 2.0 with some additional features, such as the ASP.NET AJAX framework and LINQ.

<?xml version="1.0"?>
<configuration>
   <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>
   
   <appSettings/>
   <connectionStrings/>

   <system.web>
      <compilation debug="false" strict="false" explicit="true">
         <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
         </assemblies>
      </compilation>

      <pages>
         <namespaces>
            <clear/>
            <add namespace="System"/>
            <add namespace="System.Collections"/>
            <add namespace="System.Collections.Generic"/>
            <add namespace="System.Collections.Specialized"/>
            <add namespace="System.Configuration"/>
            <add namespace="System.Text"/>
            <add namespace="System.Text.RegularExpressions"/>
            <add namespace="System.Linq"/>
            <add namespace="System.Xml.Linq"/>
            <add namespace="System.Web"/>
            <add namespace="System.Web.Caching"/>
            <add namespace="System.Web.SessionState"/>
            <add namespace="System.Web.Security"/>
            <add namespace="System.Web.Profile"/>
            <add namespace="System.Web.UI"/>
            <add namespace="System.Web.UI.WebControls"/>
            <add namespace="System.Web.UI.WebControls.WebParts"/>
            <add namespace="System.Web.UI.HtmlControls"/>
         </namespaces>

         <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
         </controls>
      </pages>

      <authentication mode="Windows"/>

      <httpHandlers>
         <remove verb="*" path="*.asmx"/>
         <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
         <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
         <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpHandlers>

      <httpModules>
         <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>
   </system.web>

   <system.codedom>
      <compilers>
         <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="WarnAsError" value="false"/></compiler>
         <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="OptionInfer" value="true"/>
            <providerOption name="WarnAsError" value="false"/>
         </compiler>
      </compilers>
   </system.codedom>

   <system.webServer>
         <validation validateIntegratedModeConfiguration="false"/>
      <modules>
         <remove name="ScriptModule"/>
         <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></modules>
      <handlers>
         <remove name="WebServiceHandlerFactory-Integrated"/>
         <remove name="ScriptHandlerFactory"/>
         <remove name="ScriptHandlerFactoryAppServices"/>
         <remove name="ScriptResource"/>
         <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
         <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
         <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </handlers>
   </system.webServer>

   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
         </dependentAssembly>
         <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

The <configSections> Section
The default Web.config file for ASP.NET 3.5 applications includes a <configSections> section that defines additional configuration elements. In particular, it defines a configuration section named <system.web.extensions>. In short, the <configSections> says to the ASP.NET configuration system, "Hey, you may see a section in Web.config named <system.web.extensions>. If you do, let System.Web.Configuration.SystemWebExtensionsSectionGroup parse the configuration markup." (Note that the default Web.config for ASP.NET 3.5 doesn't have a <system.web.extensions> section, it just says that such a section can appear.)

The <system.web.extensions> section is used by the ASP.NET AJAX framework for defining how Web services are called from the framework's client-side script. For more information on this section, see Configuring ASP.NET AJAX.

Additional Assemblies in the <compilation> Section
Another added feature in the default Web.config file for ASP.NET 3.5 applications is the <assemblies> element within the <compilation> element. The <assemblies> element specifies the collection of assembly names that are used in the compilation of ASP.NET pages. This section adds a few addition assemblies to the collection, namely assemblies that are new to the .NET Framework version 3.5.

When the .NET Framework version 3.5 is installed, it places these new assemblies in the machine's Global Assembly Cache (GAC).

New Namespaces in the <namespaces> Element
In addition to adding new assembly names, the default Web.config file also adds the corresponding namespaces to the <namespaces> section. In particular, two LINQ-related namespaces are added (System.Linq and System.Xml.Linq) as well as the System.Collections.Generic namespace. Generics are not new to version 3.5 - they were introduced with version 2.0 - but previously the System.Collections.Generic namespace was not imported by default.

New Control Prefixes Added Via the <controls> Section
ASP.NET 3.5 introduces two new Web controls - the ListView and DataPager - as well as a number of AJAX-related controls. In order to use these controls in an ASP.NET page, the assemblies need to be registered with a particular prefix. This registration can occur at the page-level (in the @Register directive) or in Web.config in the <controls> element. Here, the <controls> element registers two assemblies, both with the control prefix asp. In short, this registration allows for the ListView, DataPager, and AJAX-related controls in the System.Web.UI and System.Web.UI.WebControls in the System.Web.Extensions assembly to be used like: <asp:ListView runat="server" ... />.

New HTTP Handlers and Modules
The ASP.NET AJAX framework use a variety of HTTP Handlers and Modules. These Handlers and Modules do different things, from returning the script used by the framework to perform asynchronous postbacks to allowing for Web Service message calls to be encoded using JSON (as opposed to XML).

The <system.codedom> Section
The Microsoft .NET Framework CodeDom, or Code Document Object Model, is a variety of classes that can be used to dynamically generate and compile and execute code at runtime. Visual Studio 2008 offers tools that allow a developer to create data access models that get converted into code at runtime. This conversion from a data model to code is possible because of the CodeDom.

The <system.codedom> section in Web.config provides instructions as to how the CodeDom should compile the source code at runtime. In particular, the markup in the default Web.config for ASP.NET 3.5 applications instructs the CodeDom to compile against the .NET Framework version 3.5. For more information on the CodeDom, check out Brian Korzeniowski's article, Microsoft .NET CodeDom Technology.

Web Server Settings in <system.webServer>
The <system.webServer> section removes the AJAX-related HTTP Handlers and Modules added in the httpHandlers and httpModules section, and readds them with configuration settings that allow these Handlers and Modules to be used in IIS 7's integrated pipeline.

In short, the latest version of Microsoft's production-grade Web server software, IIS, allows for the ASP.NET and IIS pipelines to be integrated so that managed HTTP Modules and Handlers can execute during IIS's native pipeline workflow. This integration allows for features like forms authentication and URL authorization to be used for any incoming resource (not just ASP.NET resources). For more information, see How to Take Advantage of the IIS 7 Integrated Pipline

If you are not using IIS 7, you can remove the <system.webServer> section altogether, although there is no harm in leaving it as-is.

Updated <assemblyBinding>s
Prior to ASP.NET 3.5, the ASP.NET AJAX framework was implemented as a stand-alone assembly (System.Web.Extensions). The .NET Framework version 3.5 usurped the AJAX framework, making it part of the framework. The <assemblyBinding>s section in the default Web.config file for ASP.NET 3.5 applications simply states that any references to the pre-3.5 version of the ASP.NET AJAX framework should, instead, use the version that's part of the 3.5 framework.

Conclusion
The default Web.config generated by Visual Studio 2008 can look quite intimidating since it includes a plethora of configuration elements not found in the default Web.config file generated by Visual Studio 2005. Moreover, these additional configuration elements are automatically added when opening a 2.0 application in Visual Studio 2008. These added configuration elements update the application so that it can seamlessly utilize the new 3.5 features, such as the ASP.NET AJAX framework and LINQ.

Happy Programming!

  • By Scott Mitchell


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
    Microsoft Article: 7.0, Microsoft's Lucky Version?
    Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Windows Server 2008
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES