Modify the ASP.net version of the IIS directory

Source: Internet
Author: User
Tags iis modify
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 ());



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.