Can I use DirectoryEntry to list sites within IIS Express

一世执手 提交于 2019-12-08 05:36:12

问题


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.

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.

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;

回答1:


you can try something like this

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);
       }
}


来源:https://stackoverflow.com/questions/13696206/can-i-use-directoryentry-to-list-sites-within-iis-express

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!