Solve the web installer cannot choose the installation directory problem (3)

xiaoxiao2021-03-06  33

CREATEBDIR.CS file

Using system; using system.directoryservices; usingspace setWebdir {////

/// iismanager's summary description.

/// 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;} ///

/// define common properties /// public void get_AnonymousUser () {_AnonymousUserPass = "IUSR_DEVE-SERVER"; _AnonymousUserName = "IUSR_DEVE-SERVER"; VirtualDirectory vDir; try {Hashtable myList = ( Hashtable; idictionaryenumerator myenumerator = myList.GeEnumerator (); while (myenumerator.movenext ()) {vdir = (virtualdirectory) myenumerator.value; if (vdir.anonymoususeusername! = "&& ! VDir.AnonymousUserPass = "") {_AnonymousUserName = vDir.AnonymousUserName; _AnonymousUserPass = vDir.AnonymousUserPass; break;}}} catch {_AnonymousUserPass = "IUSR_DEVE-SERVER"; _AnonymousUserName = "IUSR_DEVE-SERVER";}} public string AnonymousUserName { Get {return_AnonymoususerName;} set {_anonymoususeusername = value;}} public string anonymoususeuserpass {get {return_anonymoususerpass;} set {_anonymoususerpass = value;

}}} // 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;}} ///

/// definition public method /// // Connection server public void connection () {connectionTOSERVER ();} // to facilitate overloaded public void Connect (string strServer) {_server = strServer; ConnectToServer ();} // overloaded to facilitate public void Connect (string strServer, string strWebSite) {_server = strServer; _website = strWebSite; ConnectToServer (); } // determines whether the virtual storage directory public bool Exists (string strVirdir) {return _virdirs.Contains (strVirdir);} // add a virtual directory public bool Create (VirtualDirectory newdir) {string strPath = "IIS: //" _Server "/ w3svc /" _Website "/ root /" newdir.name; if (! _ virdirs.contains (newdir.name) || _batchflag) {try {// Add to root Children collection to DirectoryEntry newVirDir = rootfolder.Children.Add (newdir.Name, "IIsWebVirtualDir"); newVirDir.Invoke ( "AppCreate", true); newVirDir.CommitChanges (); rootfolder.CommitChanges (); // then the update data UpdateDirInfo (newVirDir, newdir );} 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 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;

}} ///

/// VirtualDirectory type /// 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; /// /// constructor /// public VirtualDirectory () {SetValue ();} public VirtualDirectory (string sVirDirName) {SetValue (); _name = sVirDirName;} // sVirDirName: virtual path; // strPhyPath: physical path (physics path) public VirtualDirectory (string sVirDirName, string strPhyPath, string [] AnonymousUser) {SetValue (); _name = sVirDirName; _path = strPhyPath; _ausername = AnonymousUser [0]; _auserpass = AnonymousUser [1];} private void SetValue () {_read = true; _execute = false; _script = true; _ssl = false; _write = false; _authbasic = false; _authntlm = true ; _indexed = true; _ndirbrow = false; _endefaultdo C = true; _flag = 1; _defaultdoc = "default.htm, default.aspx, default.asp, index.htm"; _path = "c: //"; _AUSERNAME = "IUSR_DEVE-Server"; _ auserpass = "IUSR_DEVE- Server "; _ name =";} /// /// defines attributes, IISVirtualdir too many attributes /// I only have more 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 {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;} }} ///

/// Collection VirtualDirectories ///

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

New Post(0)