简体   繁体   中英

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

I have a page running under IIS 6.0 on server Foo. I have some other sites also running under IIS 6.0 on a remote server Baz. I want to ping Baz with Foo with ASP.NET to retrieve a list of sites running on it. How can I do this?

Possibly like this , except in C# instead of 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.

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

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.

Hope this works for IIS 6 (i tried it with IIS 7.5 only ;-))

I believe you can achieve this with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM