简体   繁体   中英

How do I list and create all IIS websites, folders in the websites and virtual web directories in C#

I am trying to first list all the IIS websites and the folders/virtual web directories in each (in a tree view). Then after that I would like to allow the user to select any of the above nodes and create a new virtual web directory there. I can create a virtual web directory if I know the path I plan to use but I cannot get a list of the folders/virtual web directories in a website (I can get the website list).

Use System.DirectoryServices to get the web sites from the IIS. You can find similar discussion at the following URL

http://channel9.msdn.com/forums/TechOff/78084-Extracting-list-of-web-sites-from-IIS-manager/

Funny, I just had a need to do this for IIS 7.5, I created a class IisSiteApplication with the major properties I wanted

using Microsoft.Web.Administration;


 public class IisSiteApplicationList : List<IisSiteApplication>
    {
        public IisSiteApplicationList()
        {
            ServerManager iisManager = new ServerManager();
            SiteCollection sites = iisManager.Sites;
            foreach (Site iisSite in sites)
            {
                foreach (Application iisApp in iisSite.Applications)
                {
                    IisSiteApplication app = new IisSiteApplication
                        {
                            SiteId = iisSite.Id,
                            SiteName = iisSite.Name,
                             AppName = iisApp.ToString(),
                            ApplicationPoolName = iisApp.ApplicationPoolName,
                            Directories =
                                String.Join(";", iisApp.VirtualDirectories.Select(a =>   a.PhysicalPath).ToArray())
                        };
                    Add(app);
                }
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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