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?
基础教程推荐
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
