Upgrading IIS Web site or application to ASP.NET 4.0

I want to upgrade a Web site from ASP.NET 2.0 to 4.0 without resetting IIS because it is running on a production server. The tool to do this is the ASP.NET IIS registration tool, aspnet_regiis.exe, which comes with ASP.NET 2.0 and 4.0. This tool doesn’t come with ASP.NET 3.0 and 3.5 because they’re both based on CLR 2.0. In fact, you don’t set a Web site or application to use ASP.NET 3.0 or 3.5, as IIS only knows about CLR version. See Scott’s Hanselman’s article for an excellent explanation. The .NET Framework version 4.0 comes with the new CLR 4.0 and so a new version of the tool is available.

Since I want to upgrade the Web site to ASP.NET 4.0, I’d run the 4.0 version of aspnet_regiis.exe, which is found under %systemroot%\Microsoft.NET\Framework\v4.0.303319. According to MSDN, to avoid interrupting IIS, I should use the -s switch to specify only the desired site or application as well as the -norestart switch to inhibit a restart. The value for the -s switch should be the path to the site; however, it may not be clear what this value should be.

To get a list of the paths and their registered ASP.NET version, I executed aspnet_regiis -lk and got the the following:

W3SVC/  2.0.50727.0
W3SVC/1/ROOT/   2.0.50727.0
W3SVC/1/ROOT/Reports/   2.0.50727.0
W3SVC/1/ROOT/ReportServer/      2.0.50727.0
W3SVC/1720207907/root/  2.0.50727.0
W3SVC/1749177435/Root/  2.0.50727.0
W3SVC/1749177435/Root/_layouts/images/  2.0.50727.0
W3SVC/1749177435/Root/_layouts/inc/     2.0.50727.0
W3SVC/2/Root/   2.0.50727.0
W3SVC/20/ROOT/  2.0.50727.0
W3SVC/561187009/Root/   2.0.50727.0
W3SVC/561187009/Root/_layouts/images/   2.0.50727.0
W3SVC/561187009/Root/_layouts/inc/      2.0.50727.0
W3SVC/966555668/Root/   2.0.50727.0
W3SVC/966555668/Root/_layouts/images/   2.0.50727.0
W3SVC/966555668/Root/_layouts/inc/      2.0.50727.0

The instance located at W3SVC/1/ROOT is the default Web site. However, it’s hard to say for certain which Web sites and applications the other paths are mapped to.

To find out, I opened the IIS Metabase. On a Windows Server 2003 machine, this is located at %systemroot%\system32\inetsrv\MetaBase.xml. The metabase provides a way to map a given path to the corresponding Web site or application. The following entry gives me the path for desired site, in this case SharePoint:

<IIsWebServer Location="/LM/W3SVC/561187009" ServerAutoStart="TRUE" ServerBindings=":80:" ServerComment="SharePoint - 80" />

Armed with these information, I set the desired Web site to ASP.NET 4.0 as follows:

%systemroot%\Microsoft.NET\Framework\v4.0.303319\aspnet_regiis.exe  -norestart -s W3SVC/561187009/Root

The -s switch is recursive, so this command would affect all sub-sites and applications. If you only want to change the top-level site, use the non-recursive -sn switch.

Related posts: