Switching Versions of the ASP.Net Framework - The Fast Way
page 1 of 1
Published: 02 Dec 2003
Unedited - Community Contributed
Abstract
ASP.Net supports multiple versions of the Framework running side-by-side on the same machine, but switching between them in either development or production can cause noticeable downtime and a significant delay. Here I cover a tested and proven method to quickly and easily switch between various versions.
by Web Team at ORCS Web
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 10424/ 16

When ASP.NET v1.1 was released, it became my project to find the best way to support this for our client base at ORCS Web, Inc.  We needed to be able to switch versions of the Framework per site as smoothly as possible.  Requiring everyone to move to version 1.1 wouldn't work and leaving everyone on version 1.0 wouldn't work either, so we had to have a way to pick and choose and to make the switch without interrupting other sites on the same server.

Is this for you?

Before I go any further, I should mention the reasons why this applies to the average developer as well as the system administrator.  Currently there are two released versions of ASP.NET but there are already multiple alpha and beta versions and there will continue to be more.  To be able to quickly switch between versions with just a couple clicks and keystrokes makes development and testing against multiple frameworks easy.  Granted, aspnet_regiis.exe will accomplish this as I’ll mention below, but it can take over 30 seconds. Imagine being able to immediately switch between Version 1.0, 1.1 and 2.0 (v2.0 is in Alpha at the time of this writing) without setting up multiple sites in IIS.  If this interests you, read on because this doesn't just apply to a system administrator.

Objectives

My 4 objectives were:

  1. To be able to update a single site to the new framework
  2. To be able to revert back if desired
  3. To have an easy way for anyone on our team to be able to do it consistently and quickly
  4. To do this without affecting the other sites on the same server

Stating the Obvious

The most obvious way to do this was to use aspnet_regiis.exe supplied with ASP.NET.  To use this method I would run "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -s W3SVC/50/ROOT".  This would update the Version of the framework for the site with ID 50 and not update the other sites on this server.  It has the flexibility required to set this for the whole server, per site or even per sub-folder.  The problem I immediately ran into was that both Internet Information Server (IIS) service and Session State would reset, causing every site on the server to be down for up to 2 minutes.  Ouch.  The strange thing is that the whole server was affected, even when running this against a single site.  This met the first 3 objectives. Unfortunately all sites on that server would be affected, blowing the 4th objective out of the water.

The other option I considered is manually changing all the script mappings in the IIS snap-in.  To change this manually, select the "Home Directory" tab in IIS and click on the "Configuration" button.  The "Mappings" tab has all the mappings.  The path to the alternate aspnet_isapi.dll can be changed here.  The problem is that this didn't meet the 3rd objective because of the large number of script mappings that had to be manually changed.

Is a better solution possible?

Needless to say, I had to go back to the drawing board to find something that would work better.  My initial guess was that doing this from script would be difficult and would probably cause a similar interruption of service to IIS. Fortunately I was wrong on both points.  Not only did it turn out to be a simple undertaking but there was zero, yes zero, impact on other sites.  Even the site being changed was not affected, other than Session State being reset.  That not only met all four of my objectives, it exceeded my expectations.

The Script

Using WSH I use an Input box and ask for the server, Site ID (more on the later) and the version to change to.  Then ADSI is used to retrieve the current script mappings and do a search-and-replace from the previous version to the new version.
 
There are a number of ways to obtain the siteID in IIS.  My favorite is to go into the properties of the site from the IIS snap-in and click on the "Properties" button in the Logging section.  At the bottom, you'll notice a "Log file name".  It will start with W3SVC??.  For example, it might be W3SVC1 or W3SVC99.  It's the number after the W3SVC that counts.  (i.e. W3SVC1 is SiteID 1, W3SVC99 is SiteID 99).  In fact, it's an easy thing to update the script to set this by the site name rather than ID if desired.

At the risk of boring the casual reader I feel I must mention one more thing that was tested.  The script mappings are usually inherited from the default mappings for the server.  IIS uses its own storage system called the Metabase which is similar in concept to Windows Registry.  The first time a site or sub-folder within a site is assigned specific script mappings, it will write its own copy of the script mappings to its area of the metabase.  Any new changes to the script mappings will be written against the new copy.  ChangeFramework.vbs will work correctly whether or not the custom script mappings are in place.

To use this script, simply save to your computer and double-click.  This is freely available to use by all, but I request that you keep the header in place to give credit to both myself and ORCS Web, Inc.  There is no warranty whatsoever so if your computer blows up or falls over dead, don't come looking to me for help.  But, the disclaimer aside, we've been running this for over 1/2 year on live production servers and it was worked 100% of the time without incident and I personally attest to its stability and trustworthiness.

Amendment:

In response to feedback to this article I've added this amendment:

Already there are other 3rd party programs doing the same thing with an interactive GUI interface.  One great utility that was mentioned to me is: http://www.denisbauer.com/NETTools.aspx.  This does exactly what I've mentioned below but with two differences.  It is much easier to work with than the script I've given.  For many people it might be a better solution.  But, it does it using the slow method I've mentioned above so it shouldn't be used for production servers because it will cause downtime and it takes a number of seconds to complete.  If you want to script a solution or you need fast-with-no-downtime, my solution is still the way to go. 

Yet another solution we'll see later in 2004 is ASP.NET v2.0 "Whidbey".  This will include an add-on to IIS and allow you to change the framework directly within IIS.  If this uses the fast switching method I've mentioned I will probably be one of the best solutions.  At the time of this writing though that property in the Alpha version of "Whidbey" is read-only so I can't tell which method they will use.  

We can conclude though that there are many ways to do this and my method isn't necessarily the best for the developer wanting a graphical interface and not concerned about waiting a few seconds.  My method isn't meant to compete with that and I encourage you to try out Denis Bauer's tool to see if it works best for you. 

Download

The script itself can be found at http://www.orcsweb.com/articles/ChangeFramework.zip

Note: It should be pretty obvious by this doesn't install the framework itself.  It switches between versions that are already installed on your computer.

Scott Forsyth is Director of IT at ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.



User Comments

Title: good but I found a pb with 2.0   
Name: Guillaume
Date: 2009-12-15 9:31:10 AM
Comment:
Hello,
I tried to change the framework version from 1.1 to 2.0 and here is the problem :
there are extensions (as .browser or .adprototype) tht don't exist in framework 1.1. So the script won't map to 2.0 the extensions that don't exists in 1.1....
Title: Nice!   
Name: Scott Forsyth
Date: 2007-01-25 9:44:32 AM
Comment:
Hi DG,

That's an old script now, but if you updated the path, it should work. Are you sure that you have v2.0 installed on your computer? You can confirm by navigating to that folder on disk. Another thing you can do is manually change one of the script mappings. Or, if it's not a production server during prime time, you can use the ASPNET tab in IIS to change the framework version.

If aspnet_regiis with the proper commands doesn't set it, then something is off. But it sounds like you're on the right track.
Title: Nice!   
Name: DG
Date: 2007-01-24 6:12:43 PM
Comment:
Thanks for this resource and background explanation -- Very informative. I updated the script for v2.0 and all indications were that it ran succesfully, but the mappings in my virtual directory weren't updated to v2.0. Aspnet_regiis didn't update them either so it looks like I'll need to do it manually.
Title: Nice article   
Name: Pat Farrell
Date: 2006-10-18 4:13:35 PM
Comment:
Good article. You should update it for 2.0. Personally, it didn't solve my issue, but discussed some interesting concepts.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-16 4:23:06 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search