How to get quot;Browsequot; URL for web site in IIS using C#?(如何获得“浏览使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获得“浏览"使用 C# 的 IIS 中网站的 URL?


- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01