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

前端 未结 4 1029
渐次进展
渐次进展 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 19:59

    This is one way of getting the browse url

    ServerManager serverMgr = new ServerManager();
    Site site = serverMgr.Sites["YourSiteName"];
    List urls = new List();
    foreach (Binding binding in site.Bindings)
    {
        string bindingInfo = binding.BindingInformation;
        string subString = bindingInfo.Substring(2, bindingInfo.Length - 2);
        string[] adrs = subString.Split(':');
        adrs[0] = "localhost:" + adrs[0];
        urls.Add(adrs);
    }
    

提交回复
热议问题