【问题标题】:An Application which fetches IIS and App Pool details of website hosted in remote server获取远程服务器中托管的网站的 IIS 和应用程序池详细信息的应用程序
【发布时间】:2013-08-21 05:34:09
【问题描述】:

我的任务是在 C# 中创建一个 Web 应用程序,它获取托管在远程服务器(相同位置)中的网站的 IIS 和应用程序池详细信息。非常感谢任何想法或帮助!!!

-仁济

【问题讨论】:

  • 我还没有得到任何线索,阿里。从哪里开始和所有:(

标签: asp.net .net c#-4.0 iis-7


【解决方案1】:

这在某种程度上是一个广泛的问题,但为了提供帮助,您可以从以下几点开始:

  1. 在 IIS 上获取网站名称:System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
  2. 要获取网站列表和虚拟目录,请查看:How to programmatically get sites list and virtual dirs in IIS 7?
  3. 管理 IIS:http://www.codeproject.com/Articles/99634/Use-C-to-manage-IIS
  4. 获取IIS版本:How to detect IIS version using C#?
  5. 获取站点状态:Programmatically get site status from IIS, gets back COM error

我想这足以让您开始探索与 IIS 相关的所有内容,希望对您有所帮助。

【讨论】:

  • 非常感谢 Ali 的帮助。让我看看以上几点,如果有任何问题,我会尽快回复您。
  • 不客气,如果您需要进一步的帮助,请告诉我
【解决方案2】:

我也有同样的要求。在做了这么多跟踪和错误的方法后,我得到了结果。

先决条件

  • 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;

    }

【讨论】:

    猜你喜欢
    • 2022-06-23
    • 1970-01-01
    • 2016-12-28
    • 1970-01-01
    • 2012-06-02
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多