下午所有人,
我需要创建一个网页,基本上列出了我的公司内部网站。我基本上需要检查一个状态屏幕,该屏幕显示web应用程序是否已启动并运行,或者是否出现故障。我还需要对与之关联的数据库实例执行相同的操作。
我正在寻找一些信息,以帮助我在我的ASP.net 2010网站上编写一些VB代码,这些代码将为我完成每个网站的检查。
我不是100%确定如何完成这项任务,但我认为我将能够Ping的应用程序名称或此web框,这是位于?
我一直在看下面的site和代码样本,以获得一些灵感,但我似乎没有更进一步的进展。
能否有人建议最好的前进方向,并提出一些可能对我有进一步帮助的建议?
在此之前,非常感谢您。贝蒂
发布于 2013-05-08 22:16:11
我看到你用了这项技术。Net microsoft.我认为你的站点和应用程序都是用"IIS“托管的?
您应该能够使用类"DirectoryEntry“及其多个属性。您可以像这样检查网站或托管在"ISS“上的web应用程序的状态,并检查应用程序池的状态。
要使用的命名空间:System.DirectoryServices (在C#和ASP上可用)
有关"DirectoryEntry“及其属性的更多信息:DirectoryEntry Info
如下所示:
//Get the webSite ID
public static int GetWebsiteID(string websiteName)
{
string machineName = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
DirectoryEntry w3svc = new DirectoryEntry("IIS://"+machineName+"/w3svc");
int id = 1;
foreach(DirectoryEntry de in w3svc.Children)
{
if(de.SchemaClassName == "IIsWebServer" && de.Properties["ServerComment"][0].ToString() == websiteName)
{
id = int.Parse(de.Name);
}
}
return id;
}
//Check statut of webSite
public void checkStatutWebSite()
{
DirectoryEntry myWebSite = new DirectoryEntry(string.Format("IIS://" + machineName + "/w3svc/{0}/Root", GetWebsiteID("webSiteName")));
ServerState state = (ServerState)Enum.Parse(typeof(ServerState), myWebSite.Properties["ServerState"].Value.ToString())
if (state == ServerState.Stopped || state == ServerState.Paused)
{
//site is stopped
}
}
public enum ServerState
{
Unknown = 0,
Starting = 1,
Started = 2,
Stopping = 3,
Stopped = 4,
Pausing = 5,
Paused = 6,
Continuing = 7
}我希望这对你有帮助。
https://stackoverflow.com/questions/16440435
复制相似问题