C# 停止 啟動 IIS 站點

 

1. 停止、启动IIS 站台

Code

 

2. 启动、回收、停止应用程序池

如何停止和启动应用程序池呢,和停止启动IIS站台一样也是用到 DirectoryEntry 类。

这里多写一点,IIS6才有应用程序池,IIS5.X是没有应用程序池的,那么如何判断IIS的版本呢?这个可以到注册表中读取。

 

Code

 

启动、回收、停止应用程序池

            DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
      DirectoryEntry findPool = appPool.Children.Find(AppPoolName,"IIsApplicationPool");
      findPool.Invoke("Start",new object[] { }); // 启动
      appPool.CommitChanges();
      appPool.Close();

 

           DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
      DirectoryEntry findPool = appPool.Children.Find(AppPoolName,"IIsApplicationPool");
      findPool.Invoke("Stop",new object[] { }); // 停止
      appPool.CommitChanges();
      appPool.Close();

           DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
      DirectoryEntry findPool = appPool.Children.Find(AppPoolName,"IIsApplicationPool");
      findPool.Invoke("Recycle",new object[] { }); // 回收
      appPool.CommitChanges();
      appPool.Close();

这里主要用到了 DirectoryEntry 类别,DirectoryEntry是.Net给我们的一大礼物,他的名字我们就知道他的功能--目录入口。那么这个类别究竟有何用处呢。敬请等待下回分解。


 

posted on 2008-08-27 17:20  蜗牛赛跑  阅读(1172)  评论(0编辑  收藏  举报

导航