Asp. NET Operations virtual directory in IIS

Source: Internet
Author: User
asp.net|iis| virtual directory in the process of doing system development, we often encounter with asp.net to operate IIS, such as new virtual directories, change the properties of virtual directories, delete virtual directory operations, and so on, now analyzed as follows:
If the virtual directory is named "WebTest", first refer to it in the project
System.DirectoryServices.dll, then
Using System.DirectoryServices;
protected System.DirectoryServices.DirectoryEntry dirroot;
1, add a new virtual directory

DirectoryEntry Newvirdir = Dirroot. Children.add ("WebTest", "IIsWebVirtualDir");
Newvirdir.invoke ("AppCreate", true);
Newvirdir.commitchanges ();
Dirroot.commitchanges ();
2. Change Virtual directory Properties

The properties of virtual directories are more commonly used: Accessread,accesswrite,accessexecute,accessscript,defaultdoc,enabledefaultdoc,path, etc.

DirectoryEntry Dirport = Dirroot. Children.find ("WebTest", "IIsVirtualDir");
Dirport. properties["AccessRead"][0] = true;
3. Delete virtual directory

DirectoryEntry Dirport = Dirroot. Children.find ("WebTest", "IIsVirtualDir");
Dirport.invoke ("AppDelete", true);
Dirroot.commitchanges ();
Or:

Object[] part = new OBJECT[2];
Part[0] = "IIsWebVirtualDir";
PART[1] = "webtest";
Dirroot. Invoke ("Delete", part);
Dirroot.commitchanges ();

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.