C#程序中操作IIS的应用程序池与站点安排__第1页
C#程序中操作IIS的应用程序池与站点安排__第2页
C#程序中操作IIS的应用程序池与站点安排__第3页
C#程序中操作IIS的应用程序池与站点安排__第4页
C#程序中操作IIS的应用程序池与站点安排__第5页
免费预览已结束,剩余16页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、C#程序中操作IIS的应用程序池与站点安排_ 一个应用程序池可以有多个站点,一个站点只对应一个应用程序池。 编程由来: 存放在一个应用程序池里的站点过多就不便于操作,所以需把其中一些站点安排到其他程序池中。 编程题目: 用户输入一个数字或者一个数字+一个名字。程序对站点的所在应用程序池进行统计,用户输入的数字用于限制应用程序池里面的最大容量数,假如超出该容量,将把超出的站点安排到其他程序应用池,或者新建的一个应用程序池,把站点安排进去。 假如用户输入一个数字的状况,将遍历全部程序应用池;假如用户输入一个数字+一个名字的状况,将只对该名字的应用程序池进行操作;假如站点的名字和应用程序池的名字一样

2、,将不进行操作。 条件: 一、把DefautlAppPool应用程序池或者含有字符AppPool #的应用程序池里面的超出的站点安排到AppPool #?应用程序池中(?代表数字) 二、假如aspnet1应用程序池里面的网站数超出用户限制的数字,则安排到新建应用程序池的命名方式为aspnet1-?;(?代表数字,表示从属aspnet1下的分支) 三、如二设置aspnet2,aspnet3,aspnet4应用程序池 四、当网站名字和应用程序池的名字相同时,将不进行操作 。 这是我在公司里面的任务,以下是我公开的代码(还不属于最优化的代码,我把我的制作品拿出来以代表原创性,最优化的代码临时不公布,

3、如有需要,请联系博主!) 。 新建一个掌握台应用程序(C#编程语言,用法vs2021版本制作) 添加引用:System.DirectoryServices class Program static Hashtable hs = new Hashtable();/创建哈希表,保存池中的站点 static string pls;/池数组 static string nums;/应用程序池中各自包含的网站数量 static Hashtable boolhs = new Hashtable();/创建哈希表,保存池中站点数量是否满 static void Main(string args) strin

4、g strNum = Console.ReadLine();/用户输入信息 pls = GetApplicationPools();/猎取应用程序池名称数组 foreach (string i in pls)/填充哈希表key值内容 hs.Add(i, ); boolhs.Add(i, false); getpoolweb(); WebNums(); if (strNum.Length 1)/推断用户输入的数字+名称 string pw = strNum.Split( ); for (int i = 0; i pls.Length; i+) if (plsi = pw1) if (int.Pa

5、rse(numsi) int.Parse(pw0) boolhsplsi = true;/将该池定义站点数量已满 GetName(pw1, int.Parse(pw0), int.Parse(numsi); Console.WriteLine(编译完毕!); else Console.WriteLine(该+pw1.ToString()+应用程序池不需进行操作!); else/推断用户输入的数字 for (int i = 0; i pls.Length; i+) if (int.Parse(numsi) int.Parse(strNum)/假如超出 boolhsplsi = true;/将该池

6、定义站点数量已满 GetName(plsi, int.Parse(strNum), int.Parse(numsi); Console.WriteLine(编译完毕!); Console.ReadLine(); / summary / 推断网站名与应用程序池名称是否相等 / /summary / param name=wnames网站名称/param / returns相等为假/returns public static bool chname(string wnames) bool ctf = true; foreach (string i in pls) if (wnames = i) c

7、tf = false; else ctf = true; return ctf; / summary / 获得池数组对应的网站数量 / /summary static void WebNums() Liststring weblist = new Liststring(); /string poolns = pooln.Split(,); foreach (string i in pls) if (hsi.ToString() != ) weblist.Add(hsi.ToString().Split(,).Length.ToString(); else weblist.Add(0); num

8、s = weblist.ToArray(); /summary /检测应用程序池的名称 /summary /param name=AppPoolName应用程序池的名称/param /param name=c指定的限制数/param /param name=inn该池中网站的数量/param /returns/returns static void GetName(string AppPoolName, int c, int inn) int si = inn - c;/旧池中站点剩余量 string kt = hsAppPoolName.ToString().Split(,); while

9、(true) int ting = 0; foreach (string w in pls) if (boolhsw.ToString() = true) ting += 1; if (ting = pls.Length) break; for (int i = 0; i pls.Length; i+) if (boolhsplsi.ToString() = false)/假如哪个池的站点量可以容纳 int d = c - int.Parse(numsi); if (si c) for (int j = 0; j si; j+) if (chname(ktj)/推断名称是否存在 movepoo

10、l(ktj, AppPoolName, plsi);/转移站点 else for (int j = 0; j d; j+) if (chname(ktj) movepool(ktj, AppPoolName, plsi); if (si-d 0) break; si = si - d; boolhsplsi = true; /需要新建的状况 if(si0) int sy = int.Parse(Math.Ceiling(double)si / (double)c).ToString();/新建多少个 for (int j = 1; j = sy; j+) string ne = ; bool

11、bname = false; int s = 1; while (bname = false) if (AppPoolName.StartsWith(aspnet) ne = AppPoolName + - + s; else if (AppPoolName.StartsWith(DefaultAppPool) AppPoolName.StartsWith(AppPool #) ne = AppPoolName + s; bool bne = false;/推断名称是否存在 foreach (string n in pls) if (n = ne) bne = true; break; if

12、(bne = true) s += 1; else bname = true; AddAppPool(ne);/新建池 for (int i = 0; i c ; i+) if (i si) if (chname(kti)/推断名称是否存在 movepool(kti, AppPoolName, ne);/转移站点 /if (si c) / / for (int j = 0; j si; j+) / movepool(ktj, AppPoolName, plsi); / /else / / for (int j = 0; j d; j+) / movepool(ktj, AppPoolName,

13、 plsi); / si = si - c; #region 池与网站的操作(获得全部池;获得指定池的网站名称;移动网站到新池) / summary / 猎取应用程序池-数组 / /summary / returns/returns public static string GetApplicationPools() DirectoryEntry directoryEntry = new DirectoryEntry(IIS:/LOCALHOST/W3SVC/AppPools); if (directoryEntry = null) return null; Liststring list =

14、 new Liststring(); foreach (DirectoryEntry entry2 in directoryEntry.Children) PropertyCollection properties = entry2.Properties; list.Add(entry2.Name.ToString().Trim(); return list.ToArray(); / summary / 获得全部的应用程序池和对应站点 / /summary static void getpoolweb() DirectoryEntry root = null; try root = new D

15、irectoryEntry(IIS:/localhost/W3SVC); catch return; foreach (DirectoryEntry website in root.Children) try if (website.SchemaClassName != IIsWebServer) continue; string comment = website.PropertiesServerComment0.ToString(); DirectoryEntry siteVDir = website.Children.Find(Root, IISWebVirtualDir); strin

16、g poolname = ; try poolname = siteVDir.PropertiesAppPoolId0.ToString().Trim(); catch (Exception ex) Console.WriteLine(ex.Message); if (poolname = ) try poolname = website.PropertiesAppPoolId0.ToString().Trim(); catch (Exception ex) Console.WriteLine(ex.Message); /if (pooln = ) pooln = poolname; /els

17、e pooln += , + poolname; /string poolns = pooln.Split(,); foreach (string i in pls) if (i = poolname) if (hsi.ToString() = ) hsi = comment; else hsi += , + comment; catch (Exception ex) Console.WriteLine(ex.Message); root.Close(); / summary / 新建池 / /summary / param name=AppPoolName应用程序池名称/param / re

18、turns/returns public static DirectoryEntry AddAppPool(string AppPoolName) try DirectoryEntry appPool = new DirectoryEntry(IIS:/localhost/W3SVC/AppPools); DirectoryEntry findPool = null; try findPool = appPool.Children.Find(AppPoolName, IIsApplicationPool); catch (Exception) if (findPool = null) find

19、Pool = appPool.Children.Add(AppPoolName, IIsApplicationPool); findPool.CommitChanges(); appPool.CommitChanges(); /pooln += , + AppPoolName; Liststring a = new Liststring(); foreach (string b in pls) a.Add(b); a.Add(AppPoolName); pls = a.ToArray();/添加新池到数组中 WebNums(); boolhs.Add(AppPoolName, false);

20、return findPool; catch (Exception ex) Console.WriteLine(ex.Message); return null; / summary / 移动网站到新池 / /summary / param name=webns网站名称/param / param name=poolold旧池名称/param / param name=poolns新池名称/param static void movepool(string webns,string poolold, string poolns) try DirectoryEntry root = new DirectoryEntry(IIS:/localhost/W3SVC); foreach (DirectoryEntry website in root.Children) if (website.SchemaClassName != IIsWebServer) continue; string comment = website.PropertiesServerComment0.ToString(); if (comment = webns) DirectoryEntry siteVDir = website

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论