简体   繁体   English

获取在远程服务器上的IIS下运行的网站的列表?

[英]Get a list of sites running under IIS on a remote server?

I have a page running under IIS 6.0 on server Foo. 我有一个页面在服务器Foo的IIS 6.0下运行。 I have some other sites also running under IIS 6.0 on a remote server Baz. 我还有一些其他站点也在远程服务器Baz上的IIS 6.0下运行。 I want to ping Baz with Foo with ASP.NET to retrieve a list of sites running on it. 我想使用ASP.NET与Foo ping Baz,以检索在其上运行的网站的列表。 How can I do this? 我怎样才能做到这一点?

Possibly like this , except in C# instead of VB. 可能像这样 ,但用C#代替VB除外。

This tells me that using Microsoft.Web.Administration.dll is not really an option because it's not distributable and only available on IIS 7. 告诉我,使用Microsoft.Web.Administration.dll并不是真正的选择,因为它不是可分发的,仅在IIS 7上可用。

Here's a code snippet to get a list of running Web Sites using Microsoft.Web.Administration, this DLL is located here : c:\\Windows\\System32\\inetsrv\\Microsoft.Web.Administration.dll 这是一个代码片段,用于获取使用Microsoft.Web.Administration的正在运行的网站的列表,此DLL位于此处:c:\\ Windows \\ System32 \\ inetsrv \\ Microsoft.Web.Administration.dll

class Program
    {
        static void Main(string[] args)
        {
            string serverName = "localhost";
            using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote(serverName))
            {
                int counter = 1;
                foreach (var site in sm.Sites)
                {
                    Console.Write(String.Format(CultureInfo.InvariantCulture, "Site number {0} : {1}{2}", counter.ToString(), site.Name, Environment.NewLine));
                    counter++;
                }
            }
            Console.ReadLine();
        }
    }

Replace "locahost" with the remote server name. 用远程服务器名称替换“ locahost”。

Hope this works for IIS 6 (i tried it with IIS 7.5 only ;-)) 希望这适用于IIS 6(我仅在IIS 7.5上尝试过;-)

I believe you can achieve this with System.DirectoryServices 我相信您可以使用System.DirectoryServices实现

        string path = "IIS://{yourservername}/W3SVC";

        using (DirectoryEntry w3svc = new DirectoryEntry(path))
        {
            foreach (DirectoryEntry entry in w3svc.Children)
            {
                if (entry.SchemaClassName == "IIsWebServer")
                {
                    string websiteName = (string)entry.Properties["ServerComment"].Value;
                }
            }
        }

Make sure you've enabled remote IIS administration on Baz 确保已在Baz上启用远程IIS管理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式获取IIS 7中的站点列表和虚拟目录? - How to programmatically get sites list and virtual dirs in IIS 7? 从远程服务器获取远程客户端列表 - Get list of remote clients from a remote server 如何列出IIS服务器托管的所有网站(不是应用程序)? - How do you list all the web sites (not applications) being hosted by an IIS server? 如何使用 C#、WMI 和/或 System.Management 从 IIS 6.0 获取站点列表和 SSL 证书? - How to get a list of sites and SSL certificates from IIS 6.0 using C#, WMI, and/or System.Management? 从IIS获取托管网站名称 - To get the hosted web sites names from IIS 从远程服务器获取二进制文件列表 - Get Binary File List from Remote server 从VS2010调试在远程IIS服务器上运行的ASP.NET应用程序 - Debug ASP.NET application running on remote IIS Server from VS2010 以编程方式确定代码是否在IIS Express下运行 - Programmatically determine if code is running under IIS Express 当IIS在服务帐户下运行时,如何在ASP.NET中获取当前的Active Directory用户 - How to get current Active Directory user in ASP.NET when IIS is running under a service account 在IIS下运行的网站的调试dll - Debug dll of website running under IIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM