如何获得“浏览"使用 C# 的 IIS 中网站的 URL? [英] How to get "Browse" URL for web site in IIS using C#?

查看:32
本文介绍了如何获得“浏览"使用 C# 的 IIS 中网站的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 IIS 中有站点名称"网站.我可以通过 ServerManager 类.我似乎无法弄清楚如何获取它的浏览"URL,就像我在下面的屏幕截图中显示的那样?

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 get the "Browse" URL for it, like I showed on the screenshot below?

如果我去管理网站 -> 在 IIS 管理器 中浏览,它将使用如下 URL 启动 IE:

If I go to Manage Website -> Browse in the IIS Manager, it will launch the IE with a URL as such:

http://localhost:8080/app1/Default.aspx

所以我需要一个这样的 URL.

So I need to get a URL like that.

PS.请注意,我不需要启动网站本身.

PS. Note that I don't need to launch the site itself.

推荐答案

试试这个:

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<Tuple<string, string>> mylist = new List<Tuple<string, string>>();

    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++;                    
    }
}

这篇关于如何获得“浏览"使用 C# 的 IIS 中网站的 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆