IIS 8的Microsoft.Web.Administration不显示所有站点 [英] Microsoft.Web.Administration for IIS 8 does not display all sites
问题描述
我试图在一个简单的C#控制台应用程序中显示IIS 8中的所有站点(这只是一个峰值,我最终会在asp.net MVC 4应用程序中执行此操作)。
I am trying to display all sites from IIS 8 in a simple C# console application (this is just a spike, I will eventually do this in an asp.net MVC 4 application).
我将Microsoft.Web.Administration dll(从C:\ Windows \ System32 \inetsrv)复制到\ References并从那里引用它。
I copied the Microsoft.Web.Administration dll (from C:\Windows\System32\inetsrv) to \References and referenced it from there.
在我的服务器上,有3个站点:
On my server, there are 3 sites:
- 默认网站
- webdav
- Ardent
我在做以下列出所有网站:
I am doing the following to list all the sites:
static void Main(string[] args)
{
using (ServerManager serverManager = new ServerManager())
{
try
{
if (serverManager != null)
{
Console.WriteLine(serverManager.Sites.ToString());
foreach (Site site in serverManager.Sites)
{
Console.WriteLine(site.Name);
Console.Read();
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.Read();
}
}
}
问题是,当我在服务器上运行它,它只显示
The problem is that, when I run this on the server, it only displays
默认网站
我跑了
appcmd list site
并且得到了所有这三个。
and got all three.
尽管如此,我还是想使用Microsoft.Web.Administration,因为这样做比使用appcmd运行命令行更好。一个C#应用程序。
Despite this, I would really like to use Microsoft.Web.Administration, as it seems better to do that than running command lines with appcmd from a C# application.
请分享您对这可能发生的原因的见解。
谢谢。
Please share your insight on why this might be happening. Thanks.
推荐答案
正如大卫在评论中指出的那样,我犯了一个愚蠢的错误,我没有注意到。我发布此答案是为了从未答复的清单中删除问题。
As David pointed out in his comment, I made a silly mistake which I failed to observe. I am posting this answer in order to remove the question from the unanswered list.
错误是
Console.Read()
在foreach中。
这篇关于IIS 8的Microsoft.Web.Administration不显示所有站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!