2013-05-08 51 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