About Links Archives Search Feed Albums of Note


ASP.NET 4.0, Part 3: Someone has stolen web.config!

Welcome to part 3 of my tour through ASP.NET 4.0 [http://blog.hmobius.com/post/2010/02/09/ASPNET-40-Cometh.aspx]. In this instalment, we’ll be investigating the ‘new look’ web.config file for ASP.NET 4.0 websites and recapping the config file hierarchy that .NET uses.

One of the more startling changes in ASP.NET 4.0 projects is in web.config. Or, rather in the lack of web.config. In VS2008 SP1, the default web.config was 139 lines long. The new one is 6 (yes, SIX) lines long. It now looks like this:

<system.web> </system.web>

The thing with web.config is that as features have been added into ASP.NET in .NET 3.0, 3.5, 3.5SP1 and the out of band releases, web.config has grown to accommodate them. Routing worked if you added ten more lines; charting another ten and so on. As .NET 4.0 has offered the ASP.NET team a crack at refactoring their base libraries and folding some of these post-v2.0 features in, the same has been true of ASP.NET configuration. Thus the team in Building 42 have taken all 139 lines of 3.5 SP1 config and pushed all the common options – which translates to pretty much everything - into the machine-level web.config file on your server. The net result is that the brand new svelte web.config file in ASP.NET 4 is 6 lines of XML and no more.

The only settings left in your web.config then are the two compilation settings needed immediately for your project.

Intellisense is your friend for adding more of your own settings to web.config and is always available in VS2010 except when opening old web.config files with the default namespace added to the root element.

In this case, as with VS2005 and VS2008 [http://weblogs.asp.net/scottgu/archive/2005/12/02/432077.aspx], you’ll have to delete the namespace and xmlns attribute before intellisense becomes available.

The *.config hierarchy So a number of features such as Dynamic Data, routing and charting are all enabled by default for the first time. Within the machine-level web.config file. If you’re unfamiliar with the idea of the config file hierarchy, let’s review. In essence, these config files work like stylesheets, cascading values down from the least-specific machine.config file to the most specific directory-level web.config file.

You can read more about the ASP.NET Configuration hierarchy and inheritance in this MSDN article [http://msdn.microsoft.com/en-us/library/ms178685(VS.100).aspx].

Sitting to the side of this chain of config files, is aspnet.config, which you’ll find in C:.NET.0.xyz. As we’ll see later on in this series when we look at the new performance counters for ASP.NET in IIS, this is the file to alter when you need to change how IIS executes ASP.NET page requests.

Next time, we’ll look at the new config transformation files built into VS2010 that ensure your config files are correct for whichever build scenario you’re targeting them at. Happy coding!

Posted on February 16, 2010   #ASP.NET     #Geek Stuff  






← Next post    ·    Previous post →