Copy Code code 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
Copy Code code as follows:
DirectoryEntry Newvirdir = Dirroot. Children.add ("WebTest", "IIsWebVirtualDir");
Newvirdir.invoke ("AppCreate", true);
Newvirdir.commitchanges ();
Dirroot.commitchanges ();
2. Change Virtual directory Properties
Copy Code code as follows:
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
Copy Code code as follows:
DirectoryEntry Dirport = Dirroot. Children.find ("WebTest", "IIsVirtualDir");
Dirport.invoke ("AppDelete", true);
Dirroot.commitchanges ();
Or:
Copy Code code as follows:
object[] part = new OBJECT[2];
Part[0] = "IIsWebVirtualDir";
Part[1] = "webtest";
Dirroot. Invoke ("Delete", part);
Dirroot.commitchanges ();