我正在编写一个网络应用程序部署验证工具,我需要检查网络应用程序和虚拟文件夹的物理文件夹结构。
这如何在 C# 中完成?或者更一般地说,通过 C# 代码与 IIS 交互?
最佳答案
我强烈建议使用 Microsoft.Web.Administration dll 用于 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);
给予:
F:\Dev\Branches\Dev1
关于.net - 如何使用 C# 代码获取 IIS 虚拟目录和 Web 应用程序的物理路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5431713/