[英]Get a list of sites running under IIS on a remote server?
I have a page running under IIS 6.0 on server Foo. 我有一个页面在服务器Foo的IIS 6.0下运行。 I have some other sites also running under IIS 6.0 on a remote server Baz.
我还有一些其他站点也在远程服务器Baz上的IIS 6.0下运行。 I want to ping Baz with Foo with ASP.NET to retrieve a list of sites running on it.
我想使用ASP.NET与Foo ping Baz,以检索在其上运行的网站的列表。 How can I do this?
我怎样才能做到这一点?
Possibly like this , except in C# instead of VB. 可能像这样 ,但用C#代替VB除外。
This tells me that using Microsoft.Web.Administration.dll is not really an option because it's not distributable and only available on IIS 7. 这告诉我,使用Microsoft.Web.Administration.dll并不是真正的选择,因为它不是可分发的,仅在IIS 7上可用。
Here's a code snippet to get a list of running Web Sites using Microsoft.Web.Administration, this DLL is located here : c:\\Windows\\System32\\inetsrv\\Microsoft.Web.Administration.dll 这是一个代码片段,用于获取使用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();
}
}
Replace "locahost" with the remote server name. 用远程服务器名称替换“ locahost”。
Hope this works for IIS 6 (i tried it with IIS 7.5 only ;-)) 希望这适用于IIS 6(我仅在IIS 7.5上尝试过;-)
I believe you can achieve this with System.DirectoryServices
我相信您可以使用
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;
}
}
}
Make sure you've enabled remote IIS administration on Baz 确保已在Baz上启用远程IIS管理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.