我在服务器Foo上的IIS 6.0下运行了一个页面。我还有一些其他站点也在远程服务器Baz上的IIS 6.0下运行。我想用带有ASP.NET的Foo ping Baz来检索在其上运行的站点列表。我怎么能这样做?
可能像this,除了在C#而不是VB。
This告诉我,使用Microsoft.Web.Administration.dll实际上不是一个选项,因为它不可分发,只能在IIS 7上使用。
答案 0 :(得分:4)
以下是使用Microsoft.Web.Administration获取正在运行的网站列表的代码段,此DLL位于此处:c:\ Windows \ System32 \ inetsrv \ Microsoft.Web.Administration.dll
class Program
{
static void Main(string[] args)
{
string serverName = "localhost";
using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote(serverName))
{
int counter = 1;
foreach (var site in sm.Sites)
{
Console.Write(String.Format(CultureInfo.InvariantCulture, "Site number {0} : {1}{2}", counter.ToString(), site.Name, Environment.NewLine));
counter++;
}
}
Console.ReadLine();
}
}
将“locahost”替换为远程服务器名称。
希望这适用于IIS 6(我只尝试使用IIS 7.5; - ))
答案 1 :(得分:1)
我相信你可以通过System.DirectoryServices
string path = "IIS://{yourservername}/W3SVC";
using (DirectoryEntry w3svc = new DirectoryEntry(path))
{
foreach (DirectoryEntry entry in w3svc.Children)
{
if (entry.SchemaClassName == "IIsWebServer")
{
string websiteName = (string)entry.Properties["ServerComment"].Value;
}
}
}
确保您已在Baz上启用了远程IIS管理