国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#新建站點,刪除站點函數代碼

2024-07-21 02:25:57
字體:
來源:轉載
供稿:網友

商業源碼熱門下載www.html.org.cn

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.windows.forms.design;
using system.directoryservices;
using system.reflection;
using system.text.regularexpressions;

//添加站點代碼

private void button2_click(object sender, system.eventargs e)
  {
   
   
   string newservercomment=textbox1.text;   
   string newserverip=textbox2.text;
   string newserverport=textbox3.text;   
   string newserverpath=textbox4.text;
   string newserverheader=textbox5.text;   
   //newwebsiteinfo siteinfo=new newwebsiteinfo(hostip,portnum,descofwebsite,commentofwebsite,webpath);
   newwebsiteinfo siteinfo=new newwebsiteinfo(newserverip,newserverport,newserverheader,newservercomment,newserverpath);
   string entpath = "iis://localhost/w3svc";
   directoryentry rootentry = new directoryentry(entpath);


   string newsitenum = getnewwebsiteid();

   directoryentry newsiteentry = rootentry.children.add(newsitenum, "iiswebserver");

   newsiteentry.commitchanges();

   newsiteentry.properties["serverbindings"].value = siteinfo.bindstring;

   newsiteentry.properties["servercomment"].value = siteinfo.commentofwebsite;

   newsiteentry.commitchanges();

   directoryentry vdentry = newsiteentry.children.add("root", "iiswebvirtualdir");

   vdentry.commitchanges();

   vdentry.properties["path"].value = siteinfo.webpath;

   vdentry.commitchanges();
   
    

   messagebox.show("站點"+siteinfo.commentofwebsite+"創建完成");
   

  }

//iis站點查詢代碼
  //// <summary>
  /// get and return a new website id of specify host
  /// </summary>
  /// <returns>the smallest new website id of the host</returns>
  public string getnewwebsiteid()
  {
   arraylist idlist = new arraylist();
   string tmpstr;

   string entrypath = "iis://localhost/w3svc";
   directoryentry entry = getdirectoryentry(entrypath);
  
   foreach (directoryentry child in entry.children)
   {
    if (child.schemaclassname == "iiswebserver")
    {
     tmpstr = child.name.tostring();
     idlist.add(convert.toint32(tmpstr));
    }
   }

   idlist.sort();

   int i = 1;
   foreach (int id in idlist)
   {
    if (i == id)
    {
     i++;
    }
   }

   return i.tostring();
  }

//刪除站點代碼

private void button3_click(object sender, system.eventargs e)
  {
   string newservercomment=textbox1.text;   
   string newserverip=textbox2.text;
   string newserverport=textbox3.text;   
   string newserverpath=textbox4.text;
   string newserverheader=textbox5.text;
   string newserverhost=textbox6.text;

   string sitenum = getwebsitenum(newservercomment);
   string rootpath = "iis://localhost/w3svc";
   string siteentpath =rootpath+"/"+sitenum; 
   directoryentry rootentry = getdirectoryentry(rootpath);
   directoryentry siteentry = getdirectoryentry(siteentpath);
   rootentry.children.remove(siteentry);
   rootentry.commitchanges();
   messagebox.show("站點 "+newservercomment+" 刪除完畢");
  }

  //根據站點名稱獲取站點標識符
  #region 獲取一個網站編號的方法
  public string getwebsitenum(string sitename)

  {

   regex regex = new regex(sitename);
   string tmpstr;
   string entpath = "iis://localhost/w3svc";
   directoryentry ent =new directoryentry(entpath); 

   foreach(directoryentry child in ent.children)

   {
    if(child.schemaclassname == "iiswebserver")
    {
     if(child.properties["serverbindings"].value != null)
     {
      tmpstr = child.properties["serverbindings"].value.tostring();
      if(regex.match(tmpstr).success)
      {
       return child.name;
      }
     }

     if(child.properties["servercomment"].value != null)

     {
      tmpstr = child.properties["servercomment"].value.tostring();
      if(regex.match(tmpstr).success)
      {
       return child.name;
      }
     }
    }
   }
   return "";
   
  }
  #endregion

 

#region 新iis站點信息結構體

  public struct newwebsiteinfo
  {
   private string hostip;   // the hosts ip address

   private string portnum;   // the new web sites port.generally is "80"

   private string descofwebsite; // 網站表示。一般為網站的網站名。例如"www.dns.com.cn"

   private string commentofwebsite;// 網站注釋。一般也為網站的網站名。

   private string webpath;   // 網站的主目錄。例如"e:/tmp"

   public newwebsiteinfo(string hostip, string portnum, string descofwebsite, string commentofwebsite, string webpath)

   {

    this.hostip = hostip;

    this.portnum = portnum;

    this.descofwebsite = descofwebsite;

    this.commentofwebsite = commentofwebsite;

    this.webpath = webpath;

   }


   public string bindstring

   {

    get
    {
     return string.format("{0}:{1}:{2}", hostip, portnum, descofwebsite);

    }

   }

   public string commentofwebsite  {get{return commentofwebsite;}}

   public string webpath  {get{return webpath;}}

  }

  #endregion


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都江堰市| 南城县| 健康| 娱乐| 廉江市| 望江县| 景泰县| 景洪市| 铁力市| 达州市| 安义县| 商丘市| 宜城市| 灵宝市| 邵武市| 沙洋县| 威宁| 万源市| 柘荣县| 敖汉旗| 越西县| 仙居县| 区。| 河西区| 宿迁市| 湖南省| 麟游县| 镇雄县| 咸阳市| 上高县| 永和县| 青河县| 广安市| 杨浦区| 靖宇县| 镇沅| 黎城县| 尉氏县| 瓮安县| 施秉县| 巴楚县|