ASP.Net 4 Web.Config Changes

by Heathesh 5. May 2010 06:23

UPDATE: Before using web.config transforms as indicated in point 2 below, please view this known issue: Web.config transform writes extra line break/spaces to values elements under applicationSettings section

With the release of .Net 4 and ASP.Net 4.0 there have been two major changes to the web.config that I really like. I personally think these changes address two very useful features that all developers should know about:

1. The file has been refactored

The web.config has now been refactored, and with ASP.Net 4 a lot of the settings that were previously found in the web.config file have now been moved to the machine.config file. This significantly reduces the size of the file, which I think is a great bonus.

With this change, your web.config file can be EMPTY or alternatively simply contain just the following section:

    <?xml version="1.0"?>
                <compilation targetFramework="4.0" />

2. Web.config transformations

Web.config transformations cater for moving your application between your relevant environments (e.g. Development, QA, Production). The transformations work on the relevant configurations you setup.

To create your own Configuration build with configuration transformations, create a new ASP.Net Web Application in Visual Studio 2010. Next, in the menu select "Build" and then "Configuration Manager". In the "Active Solution Configuration" drop down, select "New". Name the relevant configuration, for example I'm calling mine "Development" and copying the settings from the "Debug" configuration.

Make sure "Create new project configurations" is selected. Once you click okay, you will see your Web.config file now has a "+" next to it in your solution explorer.

If you don't see the "+", build you solution, right click the web.config file and select "Add Config Transformations".

You will see for each of your build configurations there will be a "Web.[Build Configuration Name].config" file. If you open any of these files, you will see place holders for different sections of your original web.config file.

To change settings per your relevant build configuration, check out the following MSDN Article: Web.config Transformation Syntax for Web Application Project Deployment

Happy deploying!

Tags: , , , , ,

Development | .Net | Visual Studio 2010 | VS2010

Powered by BlogEngine.NET (with enhancements by Heathesh)
Theme by Mads Kristensen (with tweeks by Heathesh)


Microsoft Certified Professional

Microsoft Certified Technology Specialist

Answer Questions


Tag cloud


<<  September 2017  >>

View posts in large calendar