这就是我的问题。我希望我能列出所有托管在本地的IIS网站。对于每一个,我都要检索站点名称,即主机名ex。("localhost: 80")和端口号。我可以检索很多信息,但找不到主机名上的信息在哪里。非常感谢。
下面是我的代码c#:
DirectoryEntry iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
foreach (DirectoryEntry site in iis.Children)
{
if (site.SchemaClassName == "IIsWebServer")
{
Console.Out.WriteLine(site.Name);
//I do not know the name of the property to find the "host"
Console.Out.WriteLine(site.Host); ???
}
}发布于 2013-01-29 17:40:37
我认为您需要将其从ServerBindings属性中解析出来。格式为IP:端口:主机名-如果它是默认网站,则主机名应为空或*。
还有SecureBindings,(因为您需要端口#),您还需要获取它。
https://stackoverflow.com/questions/14579317
复制相似问题