我的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应用程序池是否被停止了,高手帮忙,谢谢拉
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应用程序池是否被停止了,高手帮忙,谢谢拉
http://anf.hidotnet.com/26458/ShowPost.aspx
其实我以前的做法不去判断IIS的状况,而是定时去访问某个网页,反正如果没有启动的话,你也需要去启动它,那我直接call网页,可以达到这个目的,如果已经启动了,这样的操作不会造成什么影响。
1、判断是否停止,如果停止转向2;否则结束;
2、运行此web程序。而我的流程如下:
1、直接运行此web程序。对于asp.net程序来说,只要访问其中某个网页,就会使其在aspnet_xp.exe进程中挂起。至于怎么访问网页,你可以使用webclient这个类即可。
事件来源: .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.
_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();这个怎么改呢?
那么应该可以得到“IIS://localhost/W3SVC/IIsWebServer”这个对象,
你可以检查这个对象的“ServerState”属性。
ServerState Result:
1: Starting
2: Started
3: Stopping
4: Stopped
5: Pausing
6: Paused
7: Continuing
{
HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(url);
}catch{"连接有错误"}
HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();
//you can read data using "myRes.GetResponseStream"
myRes.Close();
那么应该可以得到“IIS://localhost/W3SVC/IIsWebServer”这个对象,
你可以检查这个对象的“ServerState”属性。
ServerState Result:
1: Starting
2: Started
3: Stopping
4: Stopped
5: Pausing
6: Paused
7: Continuing
qlming(心语)大哥能详细写一下吗?
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
}
}
}
还有 iisadmin ,它是root service ,停了它之后那么http /ftp /smtp 等等都会停;你的代码只需要检查 w3svc ,如果是重新启动iis ,那么要先停止 iisadmin 服务,再启动 iisadmin ,再启动 w3svc .
如:ping.aspx返回一个结果信息;client再判断一下吧;
另外,管理服务还可以直接管理远程的服务器的,但是这个需要RPC通讯端口(防火墙问题)和SYSTEM帐户(安全问题).如果可能的话,你可以写一个监控服务,安装到WEB SERVER上,用于维持你的IIS的稳定性.
{
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();
}