我的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应用程序池是否被停止了,高手帮忙,谢谢拉

解决方案 »

  1.   

    iis应用程序池为什么会被停止呢?建议查一下系统日值.
      

  2.   

    这是 出错的原因
    http://anf.hidotnet.com/26458/ShowPost.aspx
      

  3.   

    直接在启用的地方加个try  嘎嘎~~
      

  4.   

    to 我的iis应用程序池动不动就被自动停止了,我想做个小程序,自动检测iis应用程序池是否被停止,如果停止了就自动启动它,高手帮忙对于你所说的,我确实想不到什么太好的办法,
    其实我以前的做法不去判断IIS的状况,而是定时去访问某个网页,反正如果没有启动的话,你也需要去启动它,那我直接call网页,可以达到这个目的,如果已经启动了,这样的操作不会造成什么影响。
      

  5.   

    to 恩,这样也是一个办法,那我怎么访问网页呢,怎么判断它是否已经停止了,谢谢按照你的流程,应该如下:
    1、判断是否停止,如果停止转向2;否则结束;
    2、运行此web程序。而我的流程如下:
    1、直接运行此web程序。对于asp.net程序来说,只要访问其中某个网页,就会使其在aspnet_xp.exe进程中挂起。至于怎么访问网页,你可以使用webclient这个类即可。
      

  6.   

    用WebClient访问网页时,虽然iis应用程序池已经停止了,但是还是可以读取到数据,除非iis停止,怎么办啊,高手帮忙啊
      

  7.   

    to 用WebClient访问网页时,虽然iis应用程序池已经停止了,但是还是可以读取到数据,除非iis停止,怎么办啊,高手帮忙啊你的webclient发送的是http请求,例如访问某个aspx页面,本身iis是无法处理这类请求,需要转向相应的webapp去处理。
      

  8.   

    事件类型: 错误
    事件来源: .NET Runtime
    事件种类: 无
    事件 ID: 0
    日期: 2006-8-14
    事件: 13:47:44
    用户: N/A
    计算机: WD136
    描述:
    事件 ID ( 0 )的描述(在资源( .NET Runtime )中)无法找到。本地计算机可能没有必要的注册信息或消息 DLL 文件来从远程计算机显示消息。您可能可以使用 /AUXSOURCE= 标识来检索词描述;查看帮助和支持以了解详细信息。下列信息是事件的一部分: .NET Runtime version 1.1.4322.2300- Setup Error: Failed to load resources from resource file
    Please check your Setup.
      

  9.   

    上面是错误信息我是这样访问的WebClient _client=new WebClient();
    _client.BaseAddress="http://localhost/Forums/default.aspx";
    _client.Headers.Add("Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
    _client.Headers.Add("Accept-Language","zh-cn");
    _client.Headers.Add("UA-CPU","x86");
    //_client.Headers.Add("Accept-Encoding","gzip, deflate");
    _client.Headers.Add("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
    System.IO.Stream objStream=_client.OpenRead("/");
    System.IO.StreamReader _read=new System.IO.StreamReader(objStream,System.Text.Encoding.UTF8);
    textBox1.Text=_read.ReadToEnd();这个怎么改呢?
      

  10.   

    愚翁大哥,小弟不太明白你的 需要转向相应的webapp去处理。是怎么回事
      

  11.   

    在你上面的代码中不是可以取得“IIS://localhost/W3SVC”这个对象么?
    那么应该可以得到“IIS://localhost/W3SVC/IIsWebServer”这个对象,
    你可以检查这个对象的“ServerState”属性。
    ServerState Result:
             1: Starting
             2: Started
             3: Stopping
             4: Stopped
             5: Pausing
             6: Paused
             7: Continuing
      

  12.   

    try
    {
    HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(url);
    }catch{"连接有错误"}
      

  13.   

    sample code as follows:HttpWebRequest myReq =  (HttpWebRequest)WebRequest.Create("http://localhost/Forums/default.aspx");
    HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();
    //you can read data using "myRes.GetResponseStream"
    myRes.Close();
      

  14.   

    在你上面的代码中不是可以取得“IIS://localhost/W3SVC”这个对象么?
    那么应该可以得到“IIS://localhost/W3SVC/IIsWebServer”这个对象,
    你可以检查这个对象的“ServerState”属性。
    ServerState Result:
             1: Starting
             2: Started
             3: Stopping
             4: Stopped
             5: Pausing
             6: Paused
             7: Continuing
    qlming(心语)大哥能详细写一下吗?
      

  15.   

    我們也是用Knight94(愚翁) 這種方法
      

  16.   

    DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC"); System.Collections.IEnumerator enumerator = appPool.Children.GetEnumerator(); DirectoryEntry subItem;
    while (enumerator.MoveNext())
    {
    subItem = (DirectoryEntry) enumerator.Current;

    if (subItem.SchemaClassName == "IIsWebServer")
    {
    int intServerState = Convert.ToInt32(subItem.Properties["ServerState"].Value);
    switch (intServerState)
    {
    case 1: //Starting
    case 2: //Started
    case 3: //Stopping
    case 4: //Stopped
    case 5: //Pausing
    case 6: //Paused
    case 7: //Continuing
    default://Unknown
    }
    }
    }
      

  17.   

    这个简单;检查windows 服务即可。使用ServiceControllerServiceController sc = new ServiceController("W3SVC");检查ServiceControllerStatus的枚举;如果状态为ServiceControllerStatus.Paused 或 ServiceControllerStatus.Stopped 就表示该服务已经停了;那么启动它即可.iis 服务有 World Wide Web Publishing Service 也就是 W3SVC
    还有 iisadmin ,它是root service ,停了它之后那么http /ftp /smtp 等等都会停;你的代码只需要检查 w3svc ,如果是重新启动iis ,那么要先停止 iisadmin 服务,再启动 iisadmin ,再启动 w3svc .
      

  18.   

    通过访问IIS WEB SERVER的形式也很容易;你使用tcpclient 直接连接目标服务器的80端口,发送一个 get / 的执行或者使用HttpWebRequest 直接获取一个页;
    如:ping.aspx返回一个结果信息;client再判断一下吧;
    另外,管理服务还可以直接管理远程的服务器的,但是这个需要RPC通讯端口(防火墙问题)和SYSTEM帐户(安全问题).如果可能的话,你可以写一个监控服务,安装到WEB SERVER上,用于维持你的IIS的稳定性.
      

  19.   

    用笨方法把问题解决了,有更好方法的望贴一个,谢谢static void ConfigAppPool()
    {
    try
    {
    ASCIIEncoding encoding=new ASCIIEncoding();
    string postData="TextBox1=33&Button1=Button";
    byte[]  data = encoding.GetBytes(postData); HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("http://localhost/Forums/default.aspx");
    myRequest.Method = "POST";
    myRequest.ContentType="application/x-www-form-urlencoded";
    myRequest.ContentLength = data.Length;
    Stream newStream=myRequest.GetRequestStream();
    // Send the data.
    newStream.Write(data,0,data.Length);
    newStream.Close();
    }
    catch
    {
    DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
    DirectoryEntry findPool =appPool.Children.Find("AppPoolForums","IIsApplicationPool");
    findPool.Invoke("Start",null);
    appPool.CommitChanges();
    appPool.Close();
    }
    }private void timer1_Tick(object sender, System.EventArgs e)
    {
    ConfigAppPool();
    }private void Form1_Load(object sender, System.EventArgs e)
    {
    timer1.Interval = 8000;
    timer1.Start();
    }