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?
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
