IIS:C#的IIS的wwwroot目录?
如何从IIS元数据库中获取具有C#的IIS的所有(物理)wwwroot目录(主目录) 你可以叫我IIS:C#的IIS的wwwroot目录?,c#,.net,iis,C#,.net,Iis,如何从IIS元数据库中获取具有C#的IIS的所有(物理)wwwroot目录(主目录) 你可以叫我 C:\Windows\system32\inetsrv\appcmd.exe list vdir (当然,使用API获取正确的文件夹)。并筛选“site\”(对于默认站点“default Web site/”。我假设有一些API可以做到这一点(但是,对于较旧的IIS版本,这是非常面向脚本的,因此需要处理IDispatch来调用方法和属性get) 这确实需要提升IIS7和7.5上的流程(除非已授予I
C:\Windows\system32\inetsrv\appcmd.exe list vdir
(当然,使用API获取正确的文件夹)。并筛选“site\”(对于默认站点“default Web site/”。我假设有一些API可以做到这一点(但是,对于较旧的IIS版本,这是非常面向脚本的,因此需要处理IDispatch
来调用方法和属性get)
这确实需要提升IIS7和7.5上的流程(除非已授予IIS足够的权限)。您可以调用
C:\Windows\system32\inetsrv\appcmd.exe list vdir
(当然,使用API获取正确的文件夹)并过滤“site\”(对于默认站点“default Web site/”。我假设有一些API可以做到这一点(但是,对于较旧的IIS版本,这是非常面向脚本的,因此需要处理IDispatch
来调用方法和属性get)
这确实需要在IIS7和7.5上升级流程(除非已授予IIS足够的权限)。如果您使用的是IIS6: 您需要在Visual Studio的“添加引用.NET程序集”选项卡中添加对
System.DirectoryServices
的引用:
using System;
using System.DirectoryServices;
namespace ListRootAppPathsIIS6
{
class Program
{
static void Main(string[] args)
{
using (DirectoryEntry de = new DirectoryEntry("IIS://Localhost/W3SVC"))
{
foreach (DirectoryEntry w3svc in de.Children)
{
if (w3svc.SchemaClassName == "IIsWebServer")
{
string rootPath =
String.Format("IIS://Localhost/W3SVC/{0}/root", w3svc.Name);
using (DirectoryEntry root = new DirectoryEntry(rootPath))
{
string info = String.Format("{0} - {1} - {2}",
w3svc.Name,
w3svc.Properties["ServerComment"].Value,
root.Properties["Path"].Value);
Console.WriteLine(info);
}
}
}
}
Console.ReadLine();
}
}
}
如果您正在使用IIS7: 添加对
C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll的引用
using System;
using System.Linq;
using Microsoft.Web.Administration;
namespace ListRootAppPathsIIS7
{
class Program
{
static void Main(string[] args)
{
using(ServerManager serverManager = new ServerManager())
{
foreach (var site in serverManager.Sites)
{
var app = site.Applications.Where(a => a.Path == "/").First();
var vdir = app.VirtualDirectories.Where(v => v.Path == "/").First();
string info = String.Format("{0} - {1} - {2}",
site.Id,
site.Name,
Environment.ExpandEnvironmentVariables(vdir.PhysicalPath));
Console.WriteLine(info);
}
}
Console.ReadLine();
}
}
}
第一种方法(使用System.Directoryservices
)将适用于IIS7,前提是您已经安装了IIS6管理兼容性位
在这两种情况下,您都需要以管理员身份运行。如果您使用的是IIS6: 您需要在Visual Studio的“添加引用.NET程序集”选项卡中添加对
System.DirectoryServices
的引用:
using System;
using System.DirectoryServices;
namespace ListRootAppPathsIIS6
{
class Program
{
static void Main(string[] args)
{
using (DirectoryEntry de = new DirectoryEntry("IIS://Localhost/W3SVC"))
{
foreach (DirectoryEntry w3svc in de.Children)
{
if (w3svc.SchemaClassName == "IIsWebServer")
{
string rootPath =
String.Format("IIS://Localhost/W3SVC/{0}/root", w3svc.Name);
using (DirectoryEntry root = new DirectoryEntry(rootPath))
{
string info = String.Format("{0} - {1} - {2}",
w3svc.Name,
w3svc.Properties["ServerComment"].Value,
root.Properties["Path"].Value);
Console.WriteLine(info);
}
}
}
}
Console.ReadLine();
}
}
}
如果您正在使用IIS7: 添加对
C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll的引用
using System;
using System.Linq;
using Microsoft.Web.Administration;
namespace ListRootAppPathsIIS7
{
class Program
{
static void Main(string[] args)
{
using(ServerManager serverManager = new ServerManager())
{
foreach (var site in serverManager.Sites)
{
var app = site.Applications.Where(a => a.Path == "/").First();
var vdir = app.VirtualDirectories.Where(v => v.Path == "/").First();
string info = String.Format("{0} - {1} - {2}",
site.Id,
site.Name,
Environment.ExpandEnvironmentVariables(vdir.PhysicalPath));
Console.WriteLine(info);
}
}
Console.ReadLine();
}
}
}
第一种方法(使用System.Directoryservices
)将适用于IIS7,前提是您已经安装了IIS6管理兼容性位
在这两种情况下,您都需要以管理员身份运行。谢谢!这正是我需要的!谢谢!这正是我需要的!