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

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

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

2024-08-29 03:13:54
字體:
供稿:網(wǎng)友

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

翻出來共享了~

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

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

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

三個文件:

////////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ā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 年辖:市辖区| 横山县| 古浪县| 兴海县| 兴和县| 阿拉善盟| 江达县| 阳信县| 灵武市| 呼伦贝尔市| 延安市| 奉贤区| 瑞金市| 烟台市| 隆德县| 汕头市| 宣威市| 兰州市| 定南县| 容城县| 尉犁县| 穆棱市| 渭源县| 西峡县| 澜沧| 江西省| 德昌县| 磐石市| 黄冈市| 庆阳市| 永新县| 广丰县| 肃宁县| 房山区| 布尔津县| 望谟县| 孝昌县| 贵港市| 清河县| 嘉祥县| 彭阳县|