SoFunction
Updated on 2025-03-06

C# Method to modify the IIS site framework version number

This article describes the method of modifying the IIS site framework version number in C#. Share it for your reference. The details are as follows:

Use the IIS Registration Tool (Aspnet_regiis.exe) to easily update the application's script map to point to the ISAPI version associated with the tool.

For more detailed content on the IIS registration tool, please refer to MSDN.

On the console, we can use the following command to modify the version of a virtual directory:

Copy the codeThe code is as follows:
Aspnet_iis.exe –s path

We know how to modify the version of a virtual directory. The problem now is how to use programs to implement it.

The following code is compiled through Windows Xp sp2 based on .Net FrameWork 2.0:

//Create a virtual directoryDirectoryEntry dirRoot = new DirectoryEntry("IIS://localhost/W3SVC/1/Root"); 
DirectoryEntries dirs = ; 
DirectoryEntry virtualDir = ("VirtualChange", ); 
object[] objs = new object[] { true }; 
("AppCreate", objs); 
["AppFriendlyName"][0] = "VirtualChange"; 
["Path"].Value = "C:\\VirtualChange"; 
(); 
//Start the aspnet_iis.exe programstring fileName = ("windir") + @"\\Framework\v1.1.4322\aspnet_regiis.exe"; 
ProcessStartInfo startInfo = new ProcessStartInfo(fileName); 
//Processing directory pathstring path = (); 
int index = ("W3SVC"); 
path = (0, index); 
//Start the aspnet_iis.exe program and refresh the teaching book map = "-s " + path; 
 = ; 
 = false; 
 = true; 
 = true; 
 = true; 
Process process = new Process(); 
 = startInfo; 
(); 
(); 
string errors = (); 
if (errors != ) 
  throw new Exception(errors); 
(());

I hope this article will be helpful to everyone's C# programming.