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

后端 未结 3 1740
别跟我提以往
别跟我提以往 2021-01-04 19:10

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

using (ServerManager serverManager = new ServerManager()) { 

var sites = serverManager.Sites; 
foreach (Site         


        
相关标签:
3条回答
  • 2021-01-04 19:41
    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".

    0 讨论(0)
  • 2021-01-04 19:45

    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);
                  }
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-04 20:00

    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);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题