Asp.net|iis
There are already a lot of articles about creating IIS virtual directories, and I've translated one myself.
However, these articles only describe how to create and delete a virtual directory, but not how to modify a asp.net version of a virtual directory. If you have two versions installed on your machine with the. Net FrameWork, you will use the version that is used by default in IIS when you create, and the default version is not what you need. So what? Do you manually modify after deployment or do you use program modifications directly during deployment?
This article describes a method for modifying the ASP.net version of a virtual directory.
asp.net IIS Registration tool
The ASP.net IIS registration tool (Aspnet_regiis.exe) makes it easy to update script mappings for ASP.net applications to point to the ASP.net ISAPI version associated with the tool.
For more detailed information about the ASP.net IIS registration tool, refer to MSDN.
On the console we use the following command to modify the ASP.net version of a virtual directory:
Aspnet_iis.exe–s Path
We know how to modify the version of a virtual directory, now the problem is how to use the program to implement it.
The following code is compiled in Windows Xp SP2 based on the. Net FrameWork 2.0:
Create a virtual directory
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 the Aspnet_iis.exe program
String fileName = environment.getenvironmentvariable ("windir") + @ "\microsoft.net\framework\v1.1.4322\aspnet_ Regiis.exe ";
ProcessStartInfo startinfo = new ProcessStartInfo (fileName);
Working with directory paths
String path = VirtualDir.Path.ToUpper ();
int index = path. IndexOf ("w3svc");
Path = path. Remove (0, index);
Start Aspnet_iis.exe program, refresh textbooks 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 ());