IIS Control Management (Creation and Management of Web Virtual Directory)

zhaozj2021-02-17  69

(1) Createwebdir.cs use example

????? String sServer = "localhost"; ????? string virtualdir = "bug2004"; ?????????????????? // virtual directory ???? String pathdir ??? = @ "d: / mywebdirtest / bug2000" ?? // physical catalog

??? IISMANAGER IISMG = New IISMANAGER (SSERVER); ??? Iismg.connect (); ?????? IF (Iismg.exists (Virtualdir)) ??? {???? console.write (VirtualDir "is exist!"); ???} ??? Else ??? {???? Myini.iniWriteValue ("WebDir", "WebDirexist", "False");

???? Iismg.get_anonymoususeuser (); ???? string [] Anonymoususer = new string [2]; ???? anonymoususeuser [0] = Iismg.anonymoususeuseusername; ???? anonymoususer [1] = iismg.anonymoususeuserpass ;

???? VirtualDirectory newvirdir = new virtualdirectory (Virtualdir, Pathdir, Anonymoususer); ???? if (newvird)) ????? console.write (VirtualDir "created success!");??? Else ????? console.write (VirtualDir "creates unsuccessful!"); ???}

??? Iismg.close ();

(2) CREATEBDIR.CS is reposted, I have made some perfect and modified

/// ********************************************************* *********** / // ************** ??????????? ??? IIS control management class??? ???????????? ************** /// ************* Repost self: flying knife http: //www.aspcn.com ************ /// ************************************ ***************************************** USING SYSTEM; Using System.diRectoryServices; use system.collections;

Namespace CreateweBDir {? ///

? /// IISManager's summary description. ? ///

PUBLIC CLASS IISMANAGER

? {

?? // Define what needs to be used

?? private string _server, _website, _anonymoususeuserpass, _anonymoususeusername

?? Private VirtualDirectories_virdirs;

?? protected system.directoryservices.directoryentry rootfolder;

?? private bool_batchflag;

?? public iismanager ()

?? {

??? // By default, LocalHost is used, that is, access the local machine.

??? _ server = "localhost"; ??? _ Website = "1";

??? _ batchflag = false;

??}

?? Public IISMANAGER (String strserver)

?? {

??? _ server = strserver;

??? _WEBSITE = "1";

??? _ batchflag = false;

??}

?? ///

?? // Define public property ?? ///

?? public void get_anonymoususeuser () ?? {??? _ anonymoususeuserpass = "IUSR_DEVE-Server"; ??? _ anonymoususeusername = "IUSR_DEVE-Server"; ??? VirtualDirectory vdir; ??? Try ??? {???? Hashtable mylist = (havehtable) _virdirs; ???? iDictionaryEnumerator myenumerator = myList.GeteNumerator (); ???? while (myenumerator.movenext ()) ???? {????? vdir = (VirtualDirectory) Myenumerator. Value; ????? if (vdir.anonymoususeusername! = "" && vdir.anonymoususeuseuserpass! = "") ????? {?????? _ anonymoususeusername; ?????? _ anonymoususerpass = vdir.anonymoususeuserpass; ?????? Break; ?????} ????} ???}? ?????? {???? _ anonymoususerpass = "IUSR_DEVE-Server"; ?? ?? _ anonymoususername = "IUSR_DEVE-Server"; ???} ??} ?? public string anonymoususeusername ?? {??? get {return_anonymoususername;} ??? set {_anonymoususeusername = value;} ??} ?? public String anonymoususeuserpass ?? {??? get {return_anonymoususeuserpass;} ??? set {_anonymoususeuserpass = value;} ??} ?? // server attribute defines the name of the access machine, can be IP and computing name ?? Public String Server ?? {??? get {return _server;} ??? set {_server = value;} ??} ?? // Website property definition, for a number Word, for convenience, use string ?? // Generally, the first host is 1, the second host is 2, and it is pushed into a secondary public string Website ?? {??? get {return _Website;}??? Set {_Website = value;} ??}

?? // The name of the virtual directory ?? public virtualdirectories virdirs ?? {??? get {return_virdirs;} ??? set {_virdirs = value;} ??} ?? ////

?? // // definition public method ?? ///

?? // Connect the server ?? public void connection () ?? {??? connectTOSERVER (); ??} ?? / / for convenient overload ?? public void connect (String strserver) ?? {??? _ server = STRSERVER; ??? ConnectTOSERVER (); ??} ?? // For convenience overload ?? public void connection (string string string strwebsite) ?? {??? _ server = strWebsite; ???????} ?? // Decision whether this virtual directory is saved ?? public bool exists (string strircir) ?? {??? return_virdirs.contains (strVir); ??} ?? // Add a virtual directory ?? Public Bool Create (VirtualDirectory newdir) ?? {??? string strpath = "IIS: //" _Server "/ w3svc /" _Website "/ root /" newdir.name ;? ?? IF (! _ virdirs.contains (newdir.name) || _batchflag) ??? {???????????????????????? DirectoryEntry newvirdir = rootfolder.children.add (newdir.name, "iiswebvirtualdir"); ????? newvirdir.invoke ("appcreate", true); ????? newvirdir.commitchanges (); ???? Rootfolder.commitchanges (); ????? // then update the data ????? UpdatedirIrIrInfo (newvirdir, newdir); ????? Return True; ????} ???? Catch (Exception EE ) ???? {?????? // throw new exception (Ee.tostring ()); ????? Return False; ????} ???} ??? Else ??? {???? Return True; ???? // throw new exception ("this Virtual Directory is already exist"); ???} ??} ?? // get a virtual Directory? Public VirtualDirectory getVirdir (string strircir) ?? {??? 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) ?? {??? // determine if the virtual directory that needs to be changed exists ??? 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"); ???} ??} ?? // delete a virtual directory ?? public void delete (String STRVIRDIR) ?? {??? ing (_Virdirs .Contains (STRVIRDIR)) ??? {???? Object [] Paras = new object [2]; ???? Paras [0] = "iiswebvirtualdir"; // means the operation is a virtual directory ???? Paras [1] = STRVIRDIR; ???? rootfolder.invoke ("delete", paras); ???? rootfolder.commitchanges (); ???} ??? Else ??? {???? // Throw new Exception ("Can''t delete" strircir ", Because it isn''t exists"); ???} ??} ?? // Batch update ?? public void updatebatch () ?? { ??? batchupdate; ??} ?? // overload one :-) ?? public void updatebatch (VirtualDirectories vds) ?? {??? batchupdate (vds); ??} ?? ///? ? // Private method ?? ////

Public void close () ?? {??? _ virdirs.clear (); ??? _ virdirs = null; ??? rootfolder.dispose ();

??} ?? // Connect the server ?? private void connectiontoserver () ?? {??? 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); ???} ??} ?? // execute bulk update?? 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.AnonymousUserName; ??? de.Properties [ "AnonymousUserPass" ] [0] = vd.anonymoususerpass; ??? 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.enableDefaultdoc; ??? de.properties [" EnableDirBrowsing "] [0] = vd.enabledirbrowsing; ??? de.properties [" accessssl "] [0] = vd.accesssssl; ??? de.properties [" accessscript "] [0] = vd.accessscript;? ?? de.properties ["defaultdoc"] [0] = vd.defaultdoc;

??? de.properties ["path"] [0] = vd.path; ??? de.commitchanges (); ??} ?? // Get the virtual directory collection ?? Private VirtualDirector doVIRDIRDIRS (DirectoryEntries DES) ?? {??? VirtualDirectories TMPDIRS = New VirtualDirectories (); ??? foreach (DirectoryEntry de in ") ??? {???? ==" 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 .Anonymoususername = (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 ["enabledirbrow Sing "] [0]; ????? vd.accessssssl = (bool) de.properties [" accessssl "] [0]; ????? vd.accessscript = (bool) de.properties [" AccessScript " ] [0]; ????? vd.path = (string) de.properties ["pat"] [0]; ????? vd.flag = 0; ????? vd.defaultdoc = String) de.properties ["defaultdoc"] [0]; ????? tmpdirs.add (vd.name, vd); ????} ???} ??? Return TMPDIRS; ??}

?}? ///

? /// VirtualDirectory class? ///

? 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 _default;

?? ///

??/// Constructor??///

?? public virtualdirectory ()

?? {

??? setValue ();

??}

?? Public VirtualDirectory (String svirdiRName)

?? {

??? setValue ();

??? _ name = svirdirName;

??}

?? // svirdirName: virtual path;

?? // strphypath: physical path (Physics Path)

?? Public VirtualDirectory (String SvirdiRName, String Str Phphypath, String [] Anonymoususer)

?? {

??? setValue ();

??? _ name = svirdirName;

??? _ path = strphypath;

??? _ ausername = anonymoususer [0];

??? _ auserpass = anonymoususer [1];

??}

?? private void setValue ()

?? {

??? _ read = true; _execute = false; _script = true; _write = false; _write = false;

??? _ authnTLM = true; _indexed = true; _endirbrow = false; _endefaultdoc = true;

??? _ flag = 1;

??? _ defaultdoc = "default.htm, default.aspx, default.asp, index.htm";

??? _ path = "c: //";

??? _ ausername = "IUSR_DEVE-Server"; _ auserpass = "iUSR_DEVE-Server"; _ Name = ""

??}

?? ///

?? // define attributes, iisvirtualdir too many attributes ?? // I only have some important, other big guys need to add it. ?? ///

?? public int flag ?? {??? get {return _flag;} ??? set {_flag = value;} ??} ?? public bool accessread ?? {??? get {return _read;}??? Set {_read = value;} ??} ?? public bool accesswrite ?? {??? get {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 {r ETURN _PATH;} ??? set {_path = value;} ??} ?? public string defaultdoc ?? {??? get {return _defaultdoc;} ??? set {_defaultdoc = value;} ??} ?? public String anonymoususername ?? {??? get {return _ausername;} ??? set {_ausername = value;} ??} ?? public string anonymoususeuserpass ?? {??? get {return _auserpass;} ??? set {_auserpass = Value;} ??}?}? ///? // 集 VirtualDirectories? ///

? Public class VirtualDirectories:? System.Collections.Hashtable {?? public VirtualDirectories () ?? {??} ?? // add new methods ?? public VirtualDirectory Find (string strName) ?? {??? return (VirtualDirectory this [strname]; ??}?}}

转载请注明原文地址:https://www.9cbs.com/read-28940.html

New Post(0)