简体   繁体   English

如何以编程方式获取IIS 7中的站点列表和虚拟目录?

[英]How to programmatically get sites list and virtual dirs in IIS 7?

有谁知道如何以编程方式获取IIS 7中的站点列表和虚拟目录?

Check out this post - seems to be a brand-spanking new management API in the Microsoft.Web.Administration namespace: 看看这篇文章 - 似乎是Microsoft.Web.Administration命名空间中的一个品牌打击的新管理API:

http://blogs.msdn.com/carlosag/archive/2006/04/17/MicrosoftWebAdministration.aspx http://blogs.msdn.com/carlosag/archive/2006/04/17/MicrosoftWebAdministration.aspx

Here's a quick graphical overview from that blog post: 以下是该博客文章的快速图形概述:

替代文字

And here's a "The Gu" post on Cool new IIS7 Features and APIs 这是酷新IIS7功能和API的“The Gu”帖子

Something like this will find all the sites, their application and their virtual directories in your IIS7 server: 这样的东西会在IIS7服务器中找到所有站点,它们的应用程序和它们的虚拟目录:

    static void Main(string[] args)
    {
        ServerManager mgr = new ServerManager();

        foreach(Site s in mgr.Sites)
        {
            Console.WriteLine("Site {0}", s.Name);

            foreach(Application app in s.Applications)
            {
                Console.WriteLine("\tApplication: {0}", app.Path);

                foreach(VirtualDirectory virtDir in app.VirtualDirectories)
                {
                    Console.WriteLine("\t\tVirtual Dir: {0}", virtDir.Path);
                }
            }
        }

        Console.ReadLine();
    }

One important caveat to using the Microsoft.Web.Administration assembly is the code has to be running on a machine that has IIS7 installed. 使用Microsoft.Web.Administration组件的一个重要警告是代码必须在安装了IIS7的计算机上运行。

When I was developing a system to load IIS7 sites into a webpage on my windows XP machine I discovered this limitation. 当我开发一个系统将IIS7站点加载到我的Windows XP机器上的网页时,我发现了这个限制。 The API is great, I just wished I could have used it. API很棒,我只是希望我能用它。

Control IIS 7 server from Windows 2003 server programmatically 以编程方式从Windows 2003服务器控制IIS 7服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM