Method for C to modify framework version number of IIS site
- 2021-08-12 03:21:56
- OfStack
This article illustrates how C # modifies the framework version number of the IIS site. Share it for your reference. The details are as follows:
The ASP. NET IIS registration tool (Aspnet_regiis. exe) makes it easy to update the script mapping of the ASP. NET application to point to the ASP. NET ISAPI version associated with the tool.
For more details on the ASP. NET IIS registration tool, refer to MSDN.
On the console, we can modify the Asp. Net version of 1 virtual directory by using the following command:
Aspnet_iis.exe In fact, in fact, the s path
We know how to modify the version of a virtual directory, and now the problem is how to use the program to implement it.
The following code is compiled in Windows Xp sp 2 based on. Net FrameWork 2.0:
// Create 1 Virtual directories
DirectoryEntry dirRoot = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
DirectoryEntries dirs = dirRoot.Children;
DirectoryEntry virtualDir = dirs.Add("VirtualChange", dirRoot.SchemaClassName);
object[] objs = new object[] { true };
virtualDir.Invoke("AppCreate", objs);
virtualDir.Properties["AppFriendlyName"][0] = "VirtualChange";
virtualDir.Properties["Path"].Value = "C:\\VirtualChange";
virtualDir.CommitChanges();
// Start aspnet_iis.exe Program
string fileName = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe";
ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
// Processing directory path
string path = virtualDir.Path.ToUpper();
int index = path.IndexOf("W3SVC");
path = path.Remove(0, index);
// Start aspnet_iis.exe Program , Refresh textbook mapping
startInfo.Arguments = "-s " + path;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
string errors = process.StandardError.ReadToEnd();
if (errors != string.Empty)
throw new Exception(errors);
Console.WriteLine(process.StandardOutput.ReadToEnd());
I hope this article is helpful to everyone's C # programming.