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 directory, change the properties of virtual directory, 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
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 ();
Delete current site public void Delete ()