我可以使用DirectoryEntry列出IIS Express中的站点吗 [英] Can I use DirectoryEntry to list sites within IIS Express

查看:66
本文介绍了我可以使用DirectoryEntry列出IIS Express中的站点吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows XP上.我们有Windows 2008服务器.需要运行IIS Express,直到我们获得具有较新版本本地OS的工作站或虚拟机.真正的IIS 7.X.

I am on Windows XP. We have Windows 2008 Servers. Need to run IIS Express until we get workstations or virtual machines with newer version of local O.S. for the real IIS 7.X.

在IIS Express中运行c#代码时,可以使用DirectoryEntry列出我的站点和虚拟目录吗?我有一些在IIS Express下设置虚拟目录的示例,因此我认为已经介绍了.现在,我想列出它们以确保它们存在.

Can I use DirectoryEntry to list my Sites and Virtual Directories when I run c# code under IIS Express? I have examples for setting up the Virtual Directories under IIS Express so that I think I have covered. Now I want to list them to ensure they exist.

有人知道如何在C#中执行此操作吗?我尝试的一小段代码会导致com异常...

Anyone know how to do this in C#? Just a small snippet of what I have been trying causes com exceptions...

DirectoryEntry iisServer = new DirectoryEntry("IIS://localhost/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root", "/");
var children = folderRoot.Children;

推荐答案

您可以尝试类似的方法

void ListVirtualDirectories(string serverName, int siteId)
{            
       DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteId + "/ROOT");

       foreach (DirectoryEntry webDir in iisServer.Children)
       {
           if (webDir.SchemaClassName.Equals("IIsWebVirtualDir"))
               Console.WriteLine("Found virtual directory {0}", webDir.Name);
       }
}

这篇关于我可以使用DirectoryEntry列出IIS Express中的站点吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆