简体   繁体   中英

ServerManager How to get site's physical path on disk?

How I can get physical path of site on a disk ?

using (ServerManager serverManager = new ServerManager()) { 

var sites = serverManager.Sites; 
foreach (Site site in sites) { 
         Console.WriteLine(site.Name); // This will return the WebSite name
        //but how i get it's path on disc ??????

}
ServerManager m = new ServerManager();  
m.Sites["default web site"].Applications["/"].VirtualDirectories["/"].PhysicalPath;

basically every site has a "root application" which must have a "root virtual directory".

Use the following code to get path

using (ServerManager serverManager = new ServerManager()) 
{ 

    var sites = serverManager.Sites; 
    foreach (Site site in sites) 
    { 

        foreach (Application app in site.Applications)
        {
            Console.WriteLine("path: {0}", app.Path);
        }
    }
}

To improve a bit what others wrote, remember if you have multiple application pools pr site you get multiple directories.

using (var iisManager = new ServerManager())
{
    SiteCollection sites = iisManager.Sites;
    foreach (var site in sites)
    {
        Console.WriteLine(site.Name);
        
        foreach(var app in site.Applications)
        {
              foreach (var virt in app.VirtualDirectories)
              {
                Console.WriteLine(site.Name);
              }
        }
    }
}

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