如何在磁盘上获取站点的物理路径?
using (ServerManager serverManager = new ServerManager()) {
var sites = serverManager.Sites;
foreach (Site site in sites) {
Console.WriteLine(site.Name); // This will return the WebSite name
//but how i get it's path on disc ??????
}
答案 0 :(得分:33)
ServerManager m = new ServerManager();
m.Sites["default web site"].Applications["/"].VirtualDirectories["/"].PhysicalPath;
基本上每个站点都有一个“根应用程序”,它必须有一个“根虚拟目录”。
答案 1 :(得分:0)
使用以下代码获取路径
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);
}
}
}
答案 2 :(得分:0)
要改进其他人写的内容,请记住,如果在站点上有多个应用程序池,则会获得多个目录。
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);
}
}
}
}