CREATEBDIR.CS file
Using system; using system.directoryservices; usingspace setWebdir {////
/// summary> public class IISManager {private string _server // need to use defined, _website, _AnonymousUserPass, _AnonymousUserName; private VirtualDirectories _virdirs; protected System.DirectoryServices.DirectoryEntry rootfolder; private bool _batchflag; public IISManager () {_server = "localhost"; // By default, use LocalHost, that is, accessed the local machine _Website = "1"; _batchflag = false;} public iismanager (String strserver) {_server = strser; _Website = "1"; _batchflag = false;} ///
}}} // server attribute defines the name of the access machine, which can be IP and calculation name public string server {get {returver;} set {_server = value;}} // Website property definition, for a number, for convenience, use String // Generally, the first host is 1, the second host is 2, and push the public string Website {get {return _Website;} set {_Website = value;}} // Virtual directory name public virtualdirector virtiRS { Get {Return_Virdirs;} set {_virdirs = value;}} ///
}} Else {return true; // throw new Exception ( "This virtual directory is already exist.");}} // get a virtual directory public VirtualDirectory GetVirDir (string strVirdir) {VirtualDirectory tmp = null; if (_virdirs.Contains (strVirdir)) {tmp = _virdirs.Find (strVirdir); ((VirtualDirectory) _virdirs [strVirdir]) flag = 2;.} else {// throw new Exception ( "This virtual directory is not exists");} return tmp } // Update a virtual directory public void update (VirtualDirectory Dir) {// Judging whether the virtual directory that needs to be changed does not exist if (_Virdirs.contains (dir.name)) {DirectoryEntry Ode = rootfolder.children.find (Dir.name "IisWebVirtualDir"; UpdatedirInfo (ODE, DIR);} else {// throw new Exception ("this Virtual Directory is not exists);}} // Remove a virtual directory public void delete (String Strvirdir) {ix (_VIRDIRS.CONTAINS (STRVIRDIR)) {Object [] Paras = New Object [2]; Paras [0] = "IisWebVirtualDir"; // Indicates the operation is the virtual directory Paras [1] = Strvird; rootfolder.invoke ("delete", paras); rootfolder.commitchanges ();} else {// throw new exception "Can''t delete" strvirdir ", because it isn''t exists.");}} // Batch update public void updatebatch () {BatchUpdate (_VIRDIRS);} // overload a public void updatebatch VirtualDirectories vds) {BatchUpdate (VDS);} public void close () {_virdirs.clear (); _VIRDIRS = NULL; rootfolder.dispose ();
} // Connection Server Private Void ConnectTOSERVER () {string strpath = "IIS: //" _server "/ w3svc /" _Website "/ root"; try {this.rootfolder = new DirectoryEntry (strpath); _Virdirs = GetVirdirs (this.rootfolder.children;} catch (exception e) {// throw new exception ("Can''t connect to the server [" _server "] ...", e);}} // perform bulk updating private void BatchUpdate (VirtualDirectories vds) {_batchflag = true; foreach (object item in vds.Values) {VirtualDirectory vd = (VirtualDirectory) item; switch (vd.flag) {case 0: break; case 1: Create ( VD); Break; Case 2: Update (VD); Break;}} _batchflag = false;} // Update Stuff PRIVATE VOID UpdatedirInfo (DirectoryEntry DE, VirtualDirectory VD) {de.properties ["AnonymoususerName"] [0] = Vd.anonymoususeusername; de.properties ["anonymoususerpass"] [0] = vd.anonymoususeuserpass; de.properties ["accessRead"] [ 0] = vd.accessread; de.properties ["accessexecute"] [0] = vd.accessexecute; de.properties ["accesswrite"] [0] = vd.accesswrite; de.properties ["authbasic"] [0] = vd.authbasic; de.properties ["authnTLM"] [0] = vd.authnTlm; de.properties ["contentindexed"] [0] = vd.contentIndexed; de.properties ["enabledefaultdoc"] [0] = VD .NableDefaultDoc; de.properties ["enabledirbrowsing"] [0] = vd.enabledirBrowsing; de.properties ["accessssl"] [0] = vd.accessssl; de.properties ["Accessscript"
] [0] = vd.accesssScript; de.properties ["defaultdoc"] [0] = vd.defaultdoc; de.properties ["path"] [0] = vd.path; de.commitchanges ();} // Gets the virtual directory collection of private VirtualDirectories GetVirDirs (DirectoryEntries des) {VirtualDirectories tmpdirs = new VirtualDirectories (); foreach (DirectoryEntry de in des) {if (de.SchemaClassName == "IIsWebVirtualDir") {VirtualDirectory vd = new VirtualDirectory (); vd. Name = de.name; vd.accessRead = (bool) de.properties ["accessread"] [0]; vd.accessExecute = (bool) de.properties ["accessexecute"] [0]; vd.accessWrite = (Bool ) de.properties ["accesswrite"] [0]; vd.anonymoususeusername = (string) de.properties ["anonymoususeusername"] [0]; vd.anonymoususeuse = (string) de.properties ["anonymoususername"] [0] Vd.authbasic = (bool) de.properties ["authbasic"] [0]; vd.authnTLM = (bool) de.properties ["AuthnTLM"] [0]; vd.contentIndexed = (bool) de.propertrt IES ["ContentIndexed"] [0]; vd.enableDefaultdoc = (bool) de.properties ["enabledeDefaultdoc"] [0]; vd.enableDirBrowsing = (bool) de.properties ["enabledirBrowsing"] [0]; vd. Accessssl = (BOOL) de.properties ["accessssl"] [0]; vd.accessscript = (bool) de.properties ["accessscript"] [0]; vd.path = (string) de.properties ["path" ] [0]; vd.flag = 0; vd.defaultdoc = (string) de.properties ["defaultdoc"] [0]; tmpdirs.add (vd.name, vd);}} Return TMPDIRS;
}} ///
/// summary> public int flag {get {return _flag;} set {_flag = value;}} public bool accessread {get {return _read;} set {_read = value;}} public bool accesswrite {Return _write;} set {_write = value;}} public bool AccessExecute {get {return _execute;} set {_execute = value;}} public bool AccessSSL {get {return _ssl;} set {_ssl = value;}} public bool AccessScript {get {return _script;} set {_script = value;}} public bool AuthBasic {get {return _authbasic;} set {_authbasic = value;}} public bool AuthNTLM {get {return _authntlm;} set {_authntlm = value;} } public bool ContentIndexed {get {return _indexed;} set {_indexed = value;}} public bool EnableDirBrowsing {get {return _endirbrow;} set {_endirbrow = value;}} public bool EnableDefaultDoc {get {return _endefaultdo c;} set {_endefaultdoc = value;}} public string Name {get {return _name;} set {_name = value;}} public string Path {get {return _path;} set {_path = value;}} public string DefaultDoc {get {return _defaultdoc;} set {_defaultdoc = value;}} public string AnonymousUserName {get {return _ausername;} set {_ausername = value;}} public string AnonymousUserPass {get {return _auserpass;} set {_auserpass = value;} }} ///