.Net how to operate IIS (source code) Author: Flying www.ASPCool.com Time: 2002-6-9 15:21:55 Views: 6619
/// ********************************************************* ************ /// ************** IIS control management class 1.0 beta ************* / // ************* Author: flying knife ************* / /// ************* * http://www.aspcn.com ************** / // ************************ FEIDAO@aspcn.com **** ********** /// ************** 2002.05.25 6 days before World Cup ************* // / ************************************************** **************; use system.directoryServices; use system.collection; namespace aspcn.management {///
/// summary> public class IISManager {private string _server // need to use defined, _website; private VirtualDirectories _virdirs; protected System.DirectoryServices.DirectoryEntry rootfolder; private bool _batchflag; public IISManager () {// Use default LocalHost, that is, accessed the local machine_Server = "localhost"; _Website = "1"; _batchflag = false;} public iismanager (String strserver) {_server = strserver; _Website = "1"; _batchflag = false;} ///
if (! _ virdirs.Contains (newdir.Name) || _batchflag) {try {// added to the ROOT Children set to DirectoryEntry newVirDir = rootfolder.Children.Add (newdir.Name, "IIsWebVirtualDir"); newVirDir.Invoke ( "Appcreate"; newvirdir.commitchanges (); rootfolder.commitchanges (); // then update data UpdatedirInfo (newvirdir, newdir);} catch (exception EE) {throw new exception;} } else {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 = _VIRDIRDIR); (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) {// Determines if the virtual directory that needs to be changed does IF (_VIRDIRDIRS.CONTAINS (Dir.Name)) {DirectoryEntry Ode = rootfolder.ch Ildren.Find (Dir.Name, "IisWebVirtualDir); UpdatedirInfo (ODE, DIR);} else {throw new exception (" this Virtual Directory is not exists (}} // Delete a virtual directory public void delete String strircir) {if (_virdirs.contains (strircir)) {Object [] Paras = new object [2]; Paras [0] = "IisWebVirtualDir"; // means operation is the virtual directory Paras [1] = STRVIRDIR; rootfolder .Invoke ("delete"; rootfolder.commitchanges ();} else {throw new Exception ("Can't delete" strvirdir ", Because it isn't exists.");}} // Batch update Public void updatebatch () {BatchUpdate (_VIRDIRS);
} // Overload one :-) public void updatebatch (VirtualDirectories vds) {BatchUpdate (VDS);} ///
] [0] = vd.accessssl; de.properties ["accessscript"] [0] = vd.accesssScript; de.properties ["defaultdoc"] [0] = vd.defaultdoc; de.properties ["path"] [ 0] = vd.Path; de.CommitChanges ();} // set the virtual directory acquired 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 ["anonymoususername"] [0]; vd. Anonymoususerpass = (string) de.properties ["anonymoususername"] [0]; vd.authbasic = (bool) de.properties ["authbasic"] [0]; vd.authnTlm = (bool) de.properties ["authntlm" ] [0]; vd.contentIndexed = (BOOL) de.properties ["contentindexed"] [0]; Vd.enableDefaultdoc = (BOOL) de.properties ["enabledefaultdoc"] [0]; vd.enabledirbrowsing = (bool) de.properties ["enabledirbrowsing"] [0]; vd.accessssssl = (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;}} ///
public class VirtualDirectory {private bool _read, _execute, _script, _ssl, _write, _authbasic, _authntlm, _indexed, _endirbrow, _endefaultdoc; private string _ausername, _auserpass, _name, _path; private int _flag; private string _defaultdoc; ///
/// 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 _endefaultdoc;} 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;}}} ///