我正在编写一个web应用程序部署验证工具,我需要检查Web应用程序和虚拟文件夹的物理文件夹结构。
在C#中如何做到这一点呢?或者更一般地说,通过C#代码与IIS交互?
发布于 2011-03-25 19:41:52
我强烈建议您使用IIS来实现出色的Microsoft.Web.Administration管理功能。
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
发布于 2011-03-25 19:24:25
你可以使用WMI来做这样的事情:
Using WMI to configure IIS。
Administering IIS programatically。
你也可以使用C#的WMI (谷歌的"WMI C#")。
所以,是的,这是可能的。
发布于 2011-03-25 19:34:39
看一下HttpRequest对象。您可以使用HttpContext.Current.Request.Url获取当前URL。
如果希望检查虚拟IIS文件夹是否存在,可以尝试对预期存在的相对URL执行Server.MapPath调用(同样可以在HttpContext对象中找到),如果映射不成功,则可以假定由相对路径指定的特定子文件夹不存在。
https://stackoverflow.com/questions/5431713
复制相似问题