麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 網(wǎng)站 > IIS > 正文

用ADSI控制IIS創(chuàng)建網(wǎng)站, 虛擬目錄…… (C#)

2024-08-29 03:13:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

 這是當(dāng)年趕工的網(wǎng)站用到的東東, 結(jié)果快做完了警察叔叔來(lái)個(gè)網(wǎng)站要備案,朋友不干了,我也停工了,

翻出來(lái)共享了~

據(jù)說(shuō),控制iis和別的ms的垃圾(ms的ftp, 用戶管理.....)可以用adsi和wmi(win2k3的才好),

參考了網(wǎng)友們的資料,有版權(quán)問(wèn)題麻煩email一下

原來(lái)是按三層寫(xiě)的代碼沒(méi)有整理, 權(quán)當(dāng)筆記,省點(diǎn)稿紙, 大家看個(gè)大概, 詳細(xì)的msdn都有!

三個(gè)文件:

////////filename: hostservice.cs

//////////////////////////////////////////////////////////////////////////////////////////////////

using system;
using system.data;

using wooyea.website.modules.hosts.dataaccess;
using wooyea.website.modules.hosts.configuration;

namespace wooyea.website.modules.hosts.business
{
 /// <summary>
 /// summary description for hostservice.
 /// </summary>
 public class hostservice
 {
  #region private fields

  private modulesettings settings;

  private int  id;
  private string name;
  private string description;
  private decimal price;   // the field in sql server is the type of smallmoney
  private string ip;
  private int  port;
  private string rootpath;
  private int  maxbandwidth;
  private int  maxconnections;
  private int  cpulimit;
  private byte serversize;
  private byte appisolated;
  #endregion

  #region properties
  
  public int id
  {
   get {return id;}
   set {id = value;}
  }

  public string name
  {
   get {return name;}
   set {name = value;}
  }

  public string description
  {
   get {return description;}
   set {description = value;}
  }

  public decimal price
  {
   get {return price;}
   set {price = value;}
  }

  public string ip
  {
   get {return ip;}
   set {ip = value;}
  }

  public int port
  {
   get {return port;}
   set {port = value;}
  }

  public string rootpath
  {
   get {return rootpath;}
   set {rootpath = value;}
  }
  
  public int maxbandwidth
  {
   get {return maxbandwidth;}
   set {maxbandwidth = value;}
  }

  public int cpulimit
  {
   get {return cpulimit;}
   set {cpulimit = value;}
  }

  public byte serversize
  {
   get {return serversize;}
   set {serversize = value;}
  }

  #endregion

  public hostservice()
  {
   configuration.moduleconfig config = new moduleconfig();
   settings = config.getsettings();
  }

  public hostservice(string name, string description, decimal price, string ip, string rootpath) : this()
  {
   this.name   = name;
   this.description = description;
   this.price   = price;
   this.ip    = ip;
   this.rootpath  = rootpath;

  }

  public hostservice(int id) : this()
  {
   this.id = id;
   getdetails();
  }

  public void getdetails()
  {
   dataaccess.hostservices datahostservices = new wooyea.website.modules.hosts.dataaccess.hostservices(settings.connectionstring);

   datarow temprow = datahostservices.getdetails(id);

   this.name  = (string)temprow["hostservicename"];
   this.price  = convert.todecimal(temprow["hostserviceprice"]);
   this.ip   = (string)temprow["hostserviceip"];
   this.port  = (int)temprow["hostserviceport"];
   this.rootpath = (string)temprow["hostservicerootpath"];

  }
  
  public dataset gethostservices()
  {
   dataaccess.hostservices datahostservices= new wooyea.website.modules.hosts.dataaccess.hostservices(settings.connectionstring);

   return datahostservices.gethostservices();
  }

  public int create()
  {
   dataaccess.hostservices datahostservices= new wooyea.website.modules.hosts.dataaccess.hostservices(settings.connectionstring);

   return datahostservices.insert(name, description, price, rootpath, ip);
  }

  public bool update()
  {
   dataaccess.hostservices datahostservices= new wooyea.website.modules.hosts.dataaccess.hostservices(settings.connectionstring);

   return datahostservices.update(id, name, description, price, rootpath, ip);
  }

 }
}
////////////end hostservice.cs/////////////////////////////////////////////////////////////////////

// filename: iismanager.cs

using system;
using system.collections;
using system.text.regularexpressions;
using system.text;
using system.directoryservices;

using wooyea.website.modules.hosts;

namespace wooyea.website.modules.hosts.business
{
 /// <summary>
 /// summary description for class1.
 /// </summary>
 class iismanager
 {

  public iismanager()
  {}

  public directoryentry getdirectoryentry(string entrypath)
  {
   // creater direntry instance depend on local or remote
   directoryentry direntry = new directoryentry(entrypath);

   return direntry;
  }

  public bool createsite(websiteinfo newsiteinfo)
  {


   string entpath = "iis://localhost/w3svc";
   directoryentry rootentry = getdirectoryentry(entpath);

   string newsiteid = getnewsiteid();

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

   newsiteentry.properties["serverbindings"].value = newsiteinfo.serverbindings;
   newsiteentry.properties["servercomment"].value = newsiteinfo.comment;
   newsiteentry.commitchanges();

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

   vdirentry.properties["path"].value = newsiteinfo.path;        //ph patth in disk
   vdirentry.commitchanges();

   return true;

  }

  /// <summary>
  /// get and return a new website id of specify host
  /// </summary>
  /// <returns>the smallest new website id of the host</returns>
  public string getnewsiteid()
  {
   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();
  }


 }
}

///////////////////end iismanager/////////////////////////////

//file name:  website.cs

using system;
using system.directoryservices;

using wooyea.website.modules.hosts.configuration;

using wooyea.website.modules.hosts.business;
using wooyea.website.modules.hosts.dataaccess;

namespace wooyea.website.modules.hosts.business
{
 /// <summary>
 /// summary description for website.
 /// </summary>
 public class website
 {
  #region private fields

  private modulesettings settings;

  private websiteinfo siteinfo;

  #endregion
  
  #region properties
 
  #endregion

  website()
  {
   configuration.moduleconfig config = new moduleconfig();
   settings = config.getsettings();
  }

  public website(string newheader, string newcomment, string newip, int newport, string newpath) : this()
  {
   this.siteinfo.header = newheader;
   this.siteinfo.ip = newip;
   this.siteinfo.port = newport;
   this.siteinfo.comment = newcomment;
   this.siteinfo.path = newpath;
  }
  /// <summary>
  /// create a new data record in website table and another one in the cross table
  /// </summary>
  /// <param name="userid">userid of current priciple</param>
  /// <returns></returns>
  public int createsite(int userid)
  {


   iismanager iis = new iismanager();
   iis.createsite(siteinfo);

   dataaccess.websites newsite = new websites(settings.connectionstring);
  
   return newsite.add(siteinfo, userid);

  }

 }
}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产一级片91 | 精品国产91一区二区三区 | 姑娘第四集免费看视频 | xxxxxx免费| 黄色毛片视频在线观看 | 久久久成人精品 | 看全色黄大色黄大片女图片 | 日产精品久久久一区二区开放时间 | 日本在线视频二区 | 婷婷久久网 | 国产午夜探花 | 成人免费网站在线观看视频 | 欧美精品亚洲人成在线观看 | 成人在线视频一区 | a视频在线免费观看 | 成人性视频欧美一区二区三区 | 久久综合九色综合久久久精品综合 | 欧美成人精品一区二区男人小说 | 大号bbwassbigav头交 | 沉沦的校花奴性郑依婷c到失禁 | 日本精品视频一区二区三区四区 | 欧日一级片 | 噜噜噜在线 | 中文字幕在线日韩 | 精品一区二区三区四区在线 | 免费观看国产视频 | www.777含羞草 | 鲁丝一区二区二区四区 | 欧美日韩在线看片 | 日韩黄色免费在线观看 | 国产91一区二区三区 | 免费a级作爱片免费观看欧洲 | 国产乱淫av | 久久久久久久久浪潮精品 | 精品国产一区二区三区四区在线 | 亚洲一区二区三区视频免费 | 毛片一级视频 | 亚洲综合视频网站 | 又黄又爽免费无遮挡在线观看 | 99国产精品国产免费观看 | 泰剧19禁啪啪无遮挡大尺度 |