How to get “Browse” URL for web site in IIS using C#?

前端 未结 4 972
渐次进展
渐次进展 2021-01-17 19:38

Say, I have the \"Site Name\" web site in the IIS. I can access most of its functions via the ServerManager class from my C# code. What I can\'t seem to figure out is how to

4条回答
  •  别那么骄傲
    2021-01-17 20:00

    Try this:

    using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote("localhost"))
    {
        int counter = 0;
        string[] ipAddress = new string[10];
        string[] sites = new string[10];
        List> mylist = new List>();
    
        foreach (var site in sm.Sites)
        {
            sites[counter] = site.Name;
    
            foreach(var bnd in site.Bindings)
                ipAddress[counter] = bnd.EndPoint != null ? 
                    bnd.EndPoint.Address.ToString() : String.Empty;
    
            mylist.Add(Tuple.Create(sites[counter], ipAddress[counter]));
                    counter++;                    
        }
    }
    

提交回复
热议问题