我认为您可以使用以下代码找到所需的内容。如果其他问题只是使用相同的方法。此代码适用于 IIS6。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.DirectoryServices;
namespace IIS_6
{
class Program
{
static void Main(string[] args)
{
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
string VirDirSchemaName = "IIsWebVirtualDir";
foreach (DirectoryEntry e in root.Children)
{
foreach (DirectoryEntry folderRoot in e.Children)
{
foreach (DirectoryEntry virtualDirectory in folderRoot.Children)
{
if (VirDirSchemaName == virtualDirectory.SchemaClassName)
{
Console.WriteLine(String.Format("\t\t{0} \t\t{1}", virtualDirectory.Name, virtualDirectory.Properties["Path"].Value));
}
}
}
}
}
}
}
关于 IIS 7,我编写了以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// to add it from %windir%\System32\InetSrv\Microsoft.Web.Administration.dll
using Microsoft.Web.Administration;
namespace IIS_7
{
class Program
{
static void Main(string[] args)
{
using (ServerManager serverManager = new ServerManager())
{
foreach (var site in serverManager.Sites)
{
Console.WriteLine(String.Format("Site: {0}", site.Name));
foreach (var app in site.Applications)
{
var virtualRoot = app.VirtualDirectories.Where(v => v.Path == "/").Single();
Console.WriteLine(String.Format("\t\t{0} \t\t{1}", app.Path, virtualRoot.PhysicalPath));
}
}
}
}
}
}