玩转苹果6splus技巧:如何用c#代码检测iis应用程序池是否启动或停止

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 08:27:56
我的iis应用程序池动不动就被自动停止了,我想做个小程序,自动检测iis应用程序池是否被停止,如果停止了就自动启动它,高手帮忙

用下面代码可以启动应用程序池
DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool =appPool.Children.Find(AppPoolName,"IIsApplicationPool");
findPool.Invoke(method,null);
appPool.CommitChanges();
appPool.Close();

用下面代码可以检查一个服务是否被启动
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController();
sc.ServiceName = AppPoolName;//"MSSQLSERVER";
if( sc.Status != ServiceControllerStatus.Running )
sc.Start();

问题是怎么用这个检测iis应用程序池是否被停止了,高手帮忙,谢谢拉

"我的iis应用程序池动不动就被自动停止了"这个应该是 程序池设置了 错误保护,当达到一定次数 自动关闭,可以在程序池的属性 运行状态 启用快速失败保护去掉对勾 就可以了

现在还需要答案吗?