How to get the IIS virtual dir & web application's physical paths with C# code?

后端 未结 3 1831
你的背包
你的背包 2020-12-06 03:41

I am writing a web application deployment verification tool and I need to check the physical folder structures of Web Applicatons and Virtual Folders.

How can this

3条回答
  •  不知归路
    2020-12-06 04:23

    I would strongly suggest using the Microsoft.Web.Administration dll for superb admin features with IIS.

    ServerManager serverManager = new ServerManager();
    
    // get the site (e.g. default)
    Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
    // get the application that you are interested in
    Application myApp = site.Applications["/Dev1"];
    
    // get the physical path of the virtual directory
    Console.WriteLine(myApp.VirtualDirectories[0].PhysicalPath);
    

    Gives:

    F:\Dev\Branches\Dev1

提交回复
热议问题