简体   繁体   English

一种应用程序,用于获取托管在远程服务器中的网站的IIS和应用程序池详细信息

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

I got a task of creating an Web application in C# ,which fetches IIS and App Pool details of Website hosted in the remote server(same location).Any idea or help is well appreciated!!! 我有一个用C#创建Web应用程序的任务,该应用程序将获取托管在远程服务器(相同位置)中的网站的IIS和应用程序池详细信息。任何想法或帮助都非常感谢!!!

-Renji -仁治

This is somehow a broad question, but in order to help here are some points you can start from: 从某种程度上来说,这是一个广泛的问题,但是为了帮助您,请从以下几点开始:

  1. get the website name at IIS: System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName() 在IIS上获取网站名称: System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
  2. to get the list of websites and virtual dirs, check this: How to programmatically get sites list and virtual dirs in IIS 7? 若要获取网站和虚拟目录列表,请检查以下内容: 如何在IIS 7中以编程方式获取站点列表和虚拟目录?
  3. to manage IIS: http://www.codeproject.com/Articles/99634/Use-C-to-manage-IIS 管理IIS: http : //www.codeproject.com/Articles/99634/Use-C-to-manage-IIS
  4. get IIS version: How to detect IIS version using C#? 获取IIS版本: 如何使用C#检测IIS版本?
  5. get site status: Programmatically get site status from IIS, gets back COM error 获取站点状态:以编程方式从IIS获取站点状态,获取COM错误

I guess this is enough for you to start exploring everything related to IIS, hope it helps. 我想这足以让您开始探索与IIS相关的所有内容,希望对您有所帮助。

I was also having the same requirement. 我也有同样的要求。 On doing so many trail and error approach I got the result. 经过这么多的跟踪和错误处理,我得到了结果。

Pre-Requisites 先决条件

  • IIS 6 and Above IIS 6及更高版本
  • .Net Framework 4.0 and Above .Net Framework 4.0及更高版本
  • Add reference to -System.DirectoryServices and Microsoft.Web.Administration 添加对-System.DirectoryServices和Microsoft.Web.Administration的引用

c# Console Application Method 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 Application Method 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.

相关问题 IIS应用程序池访问网络上的远程目录 - IIS application pool access to remote directory on network 连接到ASP.NET IIS7托管网站时出错,“ /”应用程序中出现服务器错误 - Error connecting to ASP.NET IIS7 hosted website getting error Server Error in '/' Application 使用C#Agility Pack从IIS 7中托管的代理服务器应用程序中读取网站 - Reading a website using C# Agility Pack from a proxied server application hosted in IIS 7 VS 2008中远程服务器上托管的调试网站 - Debugging website hosted on a remote server in VS 2008 找不到AJAX网址,因为Web服务器托管为IIS上另一个网站的子应用程序 - AJAX url not found because the web server is hosted as an sub app of another website on IIS 将应用程序部署到远程IIS服务器 - Deploying application to remote IIS server IIS应用程序池标识不允许服务器启动 - IIS application pool identity not allowing the server to start 回顾为每个网站/应用程序创建单独的IIS应用程序池 - Drawback to creating a separate IIS application pool for each website / application IIS 应用程序池、网站和应用程序是如何相互关联的? - How IIS application pool,website and application are related to each? 如何启用远程 Web 服务器中 IIS 中部署的 MVC 应用程序的远程调试 - How to enable remote debugging of an MVC application which was deployed in IIS in remote web server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM