2013-05-08 56 views
0

下午所有,检查内部网站是启动和运行

我需要创建一个网页,基本上列出我的公司的内部网站。我基本上需要检查一个状态屏幕,显示Web应用程序是否已启动并正在运行,或者是否失败。我也需要为它所关联的数据库实例做同样的事情。

我正在寻找一些信息来帮助我在我的ASP.net 2010网站上发布一些VB代码,这些代码将为我完成每个网站的检查。

我不是100%确定如何完成这项任务,但我想我可以Ping这个位于应用程序名称或网络盒子?

我一直在寻找以下site和代码样本的一些灵感,但我似乎没有进一步发展。

有人可以请建议最好的方法,并建议可以帮助我进一步的东西吗?

非常感谢提前。 贝蒂

回答

0

我看你使用了这项技术。网络微软。我认为您的网站和应用程序由“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 
} 

我希望这对你有所帮助。

+0

非常感谢以上。是的,我们使用IIS,并会查看System.DirectoryServices,看看我是否可以在VB中使上述情况发生。欢迎您来到 – 2013-05-08 14:28:51

+0

。 – 2013-05-08 14:55:52