簡體   English   中英

一種應用程序,用於獲取托管在遠程服務器中的網站的IIS和應用程序池詳細信息

[英]An Application which fetches IIS and App Pool details of website hosted in remote server

我有一個用C#創建Web應用程序的任務,該應用程序將獲取托管在遠程服務器(相同位置)中的網站的IIS和應用程序池詳細信息。任何想法或幫助都非常感謝!!!

-仁治

從某種程度上來說,這是一個廣泛的問題,但是為了幫助您,請從以下幾點開始:

  1. 在IIS上獲取網站名稱: System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
  2. 若要獲取網站和虛擬目錄列表,請檢查以下內容: 如何在IIS 7中以編程方式獲取站點列表和虛擬目錄?
  3. 管理IIS: http : //www.codeproject.com/Articles/99634/Use-C-to-manage-IIS
  4. 獲取IIS版本: 如何使用C#檢測IIS版本?
  5. 獲取站點狀態:以編程方式從IIS獲取站點狀態,獲取COM錯誤

我想這足以讓您開始探索與IIS相關的所有內容,希望對您有所幫助。

我也有同樣的要求。 經過這么多的跟蹤和錯誤處理,我得到了結果。

先決條件

  • IIS 6及更高版本
  • .Net Framework 4.0及更高版本
  • 添加對-System.DirectoryServices和Microsoft.Web.Administration的引用

c#控制台應用程序方法

public static SortedDictionary<string,string> GetApplicationPoolNames ( string mname = null )
    {
        try
        {
            ServerManager manager = new ServerManager ();
            SortedDictionary<string,string> ApplicationPoolStatus = new SortedDictionary<string,string> ();
            if (string.IsNullOrEmpty (mname))
                mname = System.Environment.MachineName;
            string appPoolName = string.Empty;
            manager = ServerManager.OpenRemote (mname);

            ApplicationPoolCollection applicationPoolCollection = manager.ApplicationPools;

            foreach (ApplicationPool applicationPool in applicationPoolCollection)
            {
                if (!string.IsNullOrEmpty (applicationPool.Name))
                {
                    if (!ApplicationPoolStatus.ContainsKey (applicationPool.Name))
                    {
                        ApplicationPoolStatus.Add (applicationPool.Name,string.Empty);
                    }
                    ApplicationPoolStatus[applicationPool.Name] = applicationPool.State.ToString ();
                }
            }
            return ApplicationPoolStatus;
        }
        catch (Exception)
        {
            throw;
        }
    }

ASP.Net Web / MVC應用方法

public SortedDictionary<string,string> ShowApplicationPoolDatas ()
    {
        SortedDictionary<string,string> ApplicationPoolStatus = new SortedDictionary<string,string> ();
        var domain = this.HttpContext.Request.Url.Host;
        DirectoryEntry Services = new DirectoryEntry ("IIS://"+ domain + "/W3SVC/APPPOOLS");
        foreach (DirectoryEntry Entry in Services.Children)
        {
            if (!string.IsNullOrEmpty (Entry.Name))
            {
                if (!ApplicationPoolStatus.ContainsKey (Entry.Name))
                {
                    ApplicationPoolStatus.Add (Entry.Name,string.Empty);
                }
            }
            var intStatus = (Int32)Entry.InvokeGet ("AppPoolState");
            switch (intStatus)
            {
                case 2:
                    ApplicationPoolStatus[Entry.Name] = "Running";
                    break;
                case 4:
                    ApplicationPoolStatus[Entry.Name] = "Stopped";
                    break;
                default:
                    ApplicationPoolStatus[Entry.Name] = "Unknown";
                    break;
            }
        }
        return ApplicationPoolStatus;

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM