2008-6-9
用c#怎么检测iis应用程序池是否被停止了,即它的状态
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(); } |