如何获取IIS虚拟目录&Web 应用程序的物理路径与 C# 代码? [英] How to get the IIS virtual dir & web application's physical paths with C# code?
本文介绍了如何获取IIS虚拟目录&Web 应用程序的物理路径与 C# 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个 Web 应用程序部署验证工具,我需要检查 Web 应用程序和虚拟文件夹的物理文件夹结构.
I am writing a web application deployment verification tool and I need to check the physical folder structures of Web Applicatons and Virtual Folders.
如何在 C# 中做到这一点?或者更一般地说,通过 C# 代码与 IIS 交互?
How can this be done in C#? OR more generally, interact with IIS through C# code?
推荐答案
我强烈建议使用 Microsoft.Web.Administration dll,用于使用 IIS 实现出色的管理功能.
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);
给出:
F:DevBranchesDev1
这篇关于如何获取IIS虚拟目录&Web 应用程序的物理路径与 C# 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文