0

I have found this and I need to iterate over it and to get the names of all iis websites, how to iterate over it?

I need something like:

        ServerManager iisManager = new ServerManager();
        SiteCollection sites = iisManager.Sites;

        foreach (string s in sites)
        {
         // tried to get all the sites names
        }
Martin
  • 3
  • 1
  • what does "sites" store in it. Instead of a string based iterator, use a dynamic 'var' so that you don't need to provide the type and can view its contents to chose the correct property to consume – NitinSingh Jun 05 '18 at 11:33

1 Answers1

0

You should really read about foreach loops and SideCollection class:

foreach (var site in sites)
{
    //use site.Name for site names
}

Or

foreach (Site site in sites)
{
    //use site.Name for site names
}

SiteCollection stores Site objects, which have Name property.

References: foreach loops, SideCollection class, Site class

SᴇM
  • 7,024
  • 3
  • 24
  • 41