Change the ASP.Net version of a website on IIS6 using C#.Net

Sometimes, while creating a website pragmatically, you wish to change the ASP.Net version the site is using. The following function change the ASP.Net version a website is using to ASP.Net 2.0

public static void UpdateASPNetVersion(string siteidentifier, string virtualDirectoryName)
{
   //get virtual directory and site name for m context parameters
   string targetSite = "W3SVC/" + siteidentifier + "/ROOT";
   string targetVDir = virtualDirectoryName;
   Process process = new Process();
   //run the script
   process.StartInfo.FileName =         Path.GetDirectoryName(System.Environment.SystemDirectory) + @"\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe";
   process.StartInfo.Arguments = string.Format(" -s {0}/{1}", targetSite, targetVDir);
   process.StartInfo.CreateNoWindow = false;
   process.Start();
   process.WaitForExit();
}

You can of course change the ASP.Net version to any other version by choosing a different directory.

Advertisements

One Response to Change the ASP.Net version of a website on IIS6 using C#.Net

  1. Pingback: Add users to the IIS_WPG group using C#.Net « Mohamed Fahmy Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: