国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

首頁 > 編程 > C# > 正文

用C#操縱IIS(代碼)

2020-01-24 03:50:49
字體:
供稿:網(wǎng)友

using System; 
using System.DirectoryServices; 
using System.Collections; 
using System.Text.RegularExpressions; 
using System.Text; 
/** 
 * @author 吳海燕 
 * @email  wuhy80-usual@yahoo.com 
 * 2004-6-25 第一版 
 */  
namespace Wuhy.ToolBox 

     /// <summary> 
     ///  這個(gè)類是靜態(tài)類。用來實(shí)現(xiàn)管理IIS的基本操作。 
     ///  管理IIS有兩種方式,一是ADSI,一是WMI。由于系統(tǒng)限制的原因,只好選擇使用ADSI實(shí)現(xiàn)功能。 
     ///  這是一個(gè)遺憾。只有等到只有使用IIS 6的時(shí)候,才有可能使用WMI來管理系統(tǒng) 
     ///  不過有一個(gè)問題就是,我現(xiàn)在也覺得這樣的一個(gè)方法在本地執(zhí)行會(huì)比較的好。最好不要遠(yuǎn)程執(zhí)行。 
     ///  因?yàn)槟菢有枰加孟喈?dāng)數(shù)量的帶寬,即使要遠(yuǎn)程執(zhí)行,也是推薦在同一個(gè)網(wǎng)段里面執(zhí)行 
     /// </summary> 
     public class IISAdminLib 
     { 
          #region UserName,Password,HostName的定義 
         public static string HostName 
         { 
              get 
              { 
                   return hostName; 
              } 
              set 
              { 
                   hostName = value; 
              } 
         } 
         public static string UserName 
         { 
              get 
              { 
                   return userName; 
              } 
              set 
              { 
                   userName = value; 
              } 
         } 
         public static string Password 
         { 
              get 
              { 
                   return password; 
              } 
              set 
              { 
                   if(UserName.Length <= 1) 
                   { 
                       throw new ArgumentException("還沒有指定好用戶名。請先指定用戶名"); 
                   } 
                   password = value; 
              } 
         } 
         public static void RemoteConfig(string hostName, string userName, string password) 
         { 
              HostName = hostName; 
              UserName = userName; 
              Password = password; 
         } 
          private static string hostName = "localhost"; 
          private static string userName; 
          private static string password; 
          #endregion 
          #region 根據(jù)路徑構(gòu)造Entry的方法 
         /// <summary> 
         ///  根據(jù)是否有用戶名來判斷是否是遠(yuǎn)程服務(wù)器。 
         ///  然后再構(gòu)造出不同的DirectoryEntry出來 
         /// </summary> 
         /// <param name="entPath">DirectoryEntry的路徑</param> 
         /// <returns>返回的是DirectoryEntry實(shí)例</returns> 
         public static DirectoryEntry GetDirectoryEntry(string entPath) 
         { 
              DirectoryEntry ent; 
              if(UserName == null) 
              { 
                   ent = new DirectoryEntry(entPath); 
              } 
              else 
              { 
                   //    ent = new DirectoryEntry(entPath, HostName+"http://"+UserName, Password, AuthenticationTypes.Secure); 
                   ent = new DirectoryEntry(entPath, UserName, Password, AuthenticationTypes.Secure); 
              } 
              return ent; 
         } 
          #endregion 
          #region 添加,刪除網(wǎng)站的方法 
         /// <summary> 
         ///  創(chuàng)建一個(gè)新的網(wǎng)站。根據(jù)傳過來的信息進(jìn)行配置 
         /// </summary> 
         /// <param name="siteInfo">存儲(chǔ)的是新網(wǎng)站的信息</param> 
         public static void CreateNewWebSite(NewWebSiteInfo siteInfo) 
         { 
              if(! EnsureNewSiteEnavaible(siteInfo.BindString)) 
              { 
                   throw new DuplicatedWebSiteException("已經(jīng)有了這樣的網(wǎng)站了。" + Environment.NewLine + siteInfo.BindString); 
              } 
              string entPath = String.Format("IIS://{0}/w3svc", HostName); 
              DirectoryEntry rootEntry = GetDirectoryEntry(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(); 
         } 
         /// <summary> 
         ///  刪除一個(gè)網(wǎng)站。根據(jù)網(wǎng)站名稱刪除。 
         /// </summary> 
         /// <param name="siteName">網(wǎng)站名稱</param> 
         public static void DeleteWebSiteByName(string siteName) 
         { 
              string siteNum = GetWebSiteNum(siteName); 
              string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum); 
              DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath); 
              string rootPath = String.Format("IIS://{0}/w3svc", HostName); 
              DirectoryEntry rootEntry = GetDirectoryEntry(rootPath); 
              rootEntry.Children.Remove(siteEntry); 
              rootEntry.CommitChanges(); 
         } 
          #endregion 
          #region Start和Stop網(wǎng)站的方法 
         public static void StartWebSite(string siteName) 
         { 
              string siteNum = GetWebSiteNum(siteName); 
              string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum); 
              DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath); 
              siteEntry.Invoke("Start", new object[] {}); 
         } 
         public static void StopWebSite(string siteName) 
         { 
              string siteNum = GetWebSiteNum(siteName); 
              string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum); 
              DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath); 
              siteEntry.Invoke("Stop", new object[] {}); 
         } 
          #endregion 
          #region 確認(rèn)網(wǎng)站是否相同 
         /// <summary> 
         ///  確定一個(gè)新的網(wǎng)站與現(xiàn)有的網(wǎng)站沒有相同的。 
         ///  這樣防止將非法的數(shù)據(jù)存放到IIS里面去 
         /// </summary> 
         /// <param name="bindStr">網(wǎng)站邦定信息</param> 
         /// <returns>真為可以創(chuàng)建,假為不可以創(chuàng)建</returns> 
         public static bool EnsureNewSiteEnavaible(string bindStr) 
         { 
              string entPath = String.Format("IIS://{0}/w3svc", HostName); 
              DirectoryEntry ent = GetDirectoryEntry(entPath); 
              foreach(DirectoryEntry child in ent.Children) 
              { 
                   if(child.SchemaClassName == "IIsWebServer") 
                   { 
                        if(child.Properties["ServerBindings"].Value != null) 
                       { 
                            if(child.Properties["ServerBindings"].Value.ToString() == bindStr) 
                            { 
                                 return false; 
                            } 
                       } 
                   } 
              } 
              return true; 
         } 
          #endregion 
          #region 獲取一個(gè)網(wǎng)站編號的方法 
         /// <summary> 
         ///  獲取一個(gè)網(wǎng)站的編號。根據(jù)網(wǎng)站的ServerBindings或者ServerComment來確定網(wǎng)站編號 
         /// </summary> 
         /// <param name="siteName"></param> 
         /// <returns>返回網(wǎng)站的編號</returns> 
         /// <exception cref="NotFoundWebSiteException">表示沒有找到網(wǎng)站</exception> 
         public static string GetWebSiteNum(string siteName) 
         { 
              Regex regex = new Regex(siteName); 
              string tmpStr; 
              string entPath = String.Format("IIS://{0}/w3svc", HostName); 
              DirectoryEntry ent = GetDirectoryEntry(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; 
                            } 
                       } 
                   } 
              } 
              throw new NotFoundWebSiteException("沒有找到我們想要的站點(diǎn)" + siteName); 
         } 
          #endregion 
          #region 獲取新網(wǎng)站id的方法 
         /// <summary> 
         ///  獲取網(wǎng)站系統(tǒng)里面可以使用的最小的ID。 
         ///  這是因?yàn)槊總€(gè)網(wǎng)站都需要有一個(gè)唯一的編號,而且這個(gè)編號越小越好。 
         ///  這里面的算法經(jīng)過了測試是沒有問題的。 
         /// </summary> 
         /// <returns>最小的id</returns> 
         public static string GetNewWebSiteID() 
         { 
              ArrayList list = new ArrayList(); 
              string tmpStr; 
              string entPath = String.Format("IIS://{0}/w3svc", HostName); 
              DirectoryEntry ent = GetDirectoryEntry(entPath); 
              foreach(DirectoryEntry child in ent.Children) 
              { 
                   if(child.SchemaClassName == "IIsWebServer") 
                   { 
                       tmpStr = child.Name.ToString(); 
                        list.Add(Convert.ToInt32(tmpStr)); 
                   } 
              } 
              list.Sort(); 
              int i = 1; 
              foreach(int j in list) 
              { 
                   if(i == j) 
                   { 
                       i++; 
                   } 
              } 
              return i.ToString(); 
         } 
          #endregion 
     } 
     #region 新網(wǎng)站信息結(jié)構(gòu)體 
     public struct NewWebSiteInfo 
     { 
          private string hostIP;   // The Hosts IP Address 
          private string portNum;   // The New Web Sites Port.generally is "80" 
          private string descOfWebSite; // 網(wǎng)站表示。一般為網(wǎng)站的網(wǎng)站名。例如"www.dns.com.cn" 
          private string commentOfWebSite;// 網(wǎng)站注釋。一般也為網(wǎng)站的網(wǎng)站名。 
          private string webPath;   // 網(wǎng)站的主目錄。例如"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 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
亚洲欧美日韩成人网| 浪潮av一区| 久久国产综合视频| 欧美亚洲另类在线观看| 精品国产高清自在线一区二区三区| 国产经典av| av大片在线播放| 欧美高清xxxx性| 午夜视频在线免费| 国产精品伦理一区二区三区 | 亚洲天堂二区| 美女被人操视频在线观看| 久久久久久日本一区99| 国产一区二区三区不卡免费观看| 国产福利三区| yjizz视频网站在线播放| 黄色免费av| 国产精品黄页网站在线播放免费| 香蕉视频在线观看www| 丁香花在线电影| 97国产在线| 最近中文字幕mv2018在线高清| 国产超碰在线观看| 国产永久免费| 亚洲网站一区| 国产精品毛片一区二区三区四区| 免费在线你懂的| 在线中文字幕第一页| 天堂中文在线视频| 欧美色第一页| 伊人中文字幕在线| 九九在线视频| 在线看黄网址| 国产成a人亚洲精v品| 国产亚洲精品午夜高清影院 | 亚洲精品乱码电影在线观看| 中文字幕在线播放网址| 香蕉视频在线观看网站| 精品国产白色丝袜高跟鞋| 天堂资源最新版在线视频观看免费网| 亚洲成人福利| 在线观看av网站| 最新天堂资源在线| 超碰国产在线观看| 日本在线观看| 欧美日韩综合高清一区二区| 日本成a人片在线观看| 在线免费观看黄色av| 精品国产高清a毛片无毒不卡| 午夜视频99| 国产一级影片| 国产大学生粉嫩无套流白浆| 91午夜视频| av免费在线观| www.eeuss影院| 久久综合精品视频| 懂色一区二区三区| 国产69精品久久久久孕妇国产69久久 | 亚洲永久免费网站| 亚洲欧美中文字幕在线观看 | 九九热在线视频免费观看| 九九色在线观看| 五月婷婷导航| 精精国产xxxx视频在线| 亚洲久草视频| 狠狠干在线视频| 国产欧美日韩专区| 国产精品va在线观看视色| 国产porny蝌蚪视频| 樱花草在线观看www| 欧美性猛交xxxx免费看蜜桃| 最近中文字幕mv免费高清视频8| 国产精品欧美色图| 亚洲精品视频区| 国产精品一区二区三区四区色| 国产导航在线| 免费在线黄色网址| 国产精品69一区二区三区| h网站久久久| 国产三级做爰在线观看| 欧美婷婷久久五月精品三区| 国产www视频在线观看| 香蕉视频网站在线播放| √天堂中文在线| 日本视频三区| 91九色在线看| 国产污污在线观看| 午夜在线观看91| 国产导航在线| 最新中文字幕av专区| 四虎免费视频| 精品国产一区二区三区久久久狼牙 | 国产乱码在线| 精品麻豆一区二区三区| 日韩av成人| 超碰在线免费播放| 日本欧洲一区| 在线免费观看黄色av| 国产黄色小视频| 国产网站在线播放| 日本中文字幕在线看| 国产免费av高清在线| 久久久久久国产视频| 欧美在线中文| 日本不卡1区2区3区| 精品成人一区二区三区免费视频| 国产一区二区三区不卡免费观看| 玖玖在线视频| 精品免费视频一卡2卡三卡4卡不卡| 超碰国产在线观看| 九九热视频在线观看| 日本电影在线观看| www中文字幕在线观看| 欧美96在线| 国产在线视频网站| 好吊日视频在线观看| 中文字幕亚洲精品视频| 最新国产在线精品91尤物| 国产调教视频在线观看| 国产一二区在线观看| 国产黄色一级电影| 夜夜爽视频导航| 亚洲欧美日韩一区成人| 国产经典av| 亚洲第一页在线播放| 日本片在线看| 国产精品一品| 国产极品视频| 人人干人人插| 国产精品欧美色图| 四虎成人免费观看在线网址| 免费日本黄色| 国产污污在线观看| 99re在线视频| 成人日韩欧美| 国产福利在线观看| 欧美亚洲系列| 91在线超碰| 香蕉视频在线看| 天堂在线免费视频| 99在线视频观看| 国产精品一区二三区| 精品成人免费自拍视频| 国产精品午夜久久久久久| 午夜羞羞小视频在线观看| 天堂资源中文在线| 一二三四区在线观看| 二区三区中文字幕| av超碰在线| 国产精品你懂的在线观看 | 在线观看免费黄色| 国产香蕉在线| 亚洲男人的天堂成人| 中文字幕在线免费看| av丝袜在线| 国产视频一二三区| 爱福利在线视频| 在线观看免费黄色| 国产高清大尺度一区二区不卡| 六月天色婷婷| 在线免费观看你懂的| 国产精品合集一区二区| 综合蜜桃精品| 99视频资源网| 黄色av网站在线| 丁香花高清在线观看完整版| www.三区| 国产xxxx做受性欧美88| 国产一级黄色| 久热中文字幕精品视频在线| 永久免费网站在线| 精品国内自产拍在线视频| 18加网站在线| 国产精品久久久久久福利| 日韩av成人| 最好看更新中文字幕| 最近中文字幕mv免费高清视频8| 黄色片大全在线观看| 国产网站在线免费观看| 91欧洲在线视精品在亚洲| 99在线视频影院| 青青草视频在线免费观看| 一本大道香蕉8中文在线视频| 亚洲视频精品在线观看| 国产在线视频自拍| 国产精品伦一区二区三区视频| 国产无遮挡又黄又爽免费网站| 国产网站av| 一本久久精品| 国内精品免费一区二区三区| 国产特级毛片| 日本亚洲精品| 国产午夜三区视频在线| 91亚洲天堂| 91超碰在线免费| 在线播放www| 国产丝袜精品丝袜| 中文字幕4区| 午夜av电影| 超碰免费在线播放|