C# 如何阅读IIS 6网站';使用WMI的目录结构?
我需要在IIS 6.0中使用WMI和C#读取网站文件夹。我能够使用“iisWebVirtualSetting”类读取虚拟目录和应用程序。但是,无法使用此类读取网站内的物理文件夹。 就我的情况而言,我需要阅读位于网站内的子文件夹,然后对它们设置权限。根据我的要求,我不需要处理虚拟目录/Web服务应用程序(使用下面的代码可以很容易地获得这些应用程序) 我曾尝试使用IISWebDirectory类,但它很有用 以下是读取IIS虚拟目录的代码C# 如何阅读IIS 6网站';使用WMI的目录结构?,c#,web,iis-6,wmi,directory,C#,Web,Iis 6,Wmi,Directory,我需要在IIS 6.0中使用WMI和C#读取网站文件夹。我能够使用“iisWebVirtualSetting”类读取虚拟目录和应用程序。但是,无法使用此类读取网站内的物理文件夹。 就我的情况而言,我需要阅读位于网站内的子文件夹,然后对它们设置权限。根据我的要求,我不需要处理虚拟目录/Web服务应用程序(使用下面的代码可以很容易地获得这些应用程序) 我曾尝试使用IISWebDirectory类,但它很有用 以下是读取IIS虚拟目录的代码 public static ArrayList Retrie
public static ArrayList RetrieveVirtualDirList(String ServerName, String WebsiteName)
{
ConnectionOptions options = SetUpAuthorization();
ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", ServerName), options);
scope.Connect();
String SiteId = GetSiteIDFromSiteName(ServerName, WebsiteName);
ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IISWebVirtualDirSetting");
//ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IIsSetting");
ManagementObjectSearcher WebSiteFinder = new ManagementObjectSearcher(scope, OQuery);
ArrayList WebSiteListArray = new ArrayList();
ManagementObjectCollection WebSitesCollection = WebSiteFinder.Get();
String WebSiteName = String.Empty;
foreach (ManagementObject WebSite in WebSitesCollection)
{
WebSiteName = WebSite.Properties["Name"].Value.ToString();
WebsiteName = WebSiteName.Replace("W3SVC/", "");
String extrctedSiteId = WebsiteName.Substring(0, WebsiteName.IndexOf('/'));
String temp = WebsiteName.Substring(0, WebsiteName.IndexOf('/') + 1);
String VirtualDirName = WebsiteName.Substring(temp.Length);
WebsiteName = WebsiteName.Replace(SiteId, "");
if (extrctedSiteId.Equals(SiteId))
//if (true)
{
WebSiteListArray.Add(VirtualDirName );
//WebSiteListArray.Add(WebSiteName);
//+ "|" + WebSite.Properties["Path"].Value.ToString()
}
}
return WebSiteListArray;
}
p.S:
我需要在ASP中使用WMI和C#以编程方式获取已部署站点的子文件夹。Net应用程序。我需要找出本地或远程IIS 6.0 Web服务器中现有网站的子文件夹。所以我需要一个程序化的解决方案。准确地说,如果我被指向正确的类(如iisWebVirtualSetting等),我可以用来检索网站中的物理文件夹列表,那么它将非常有用
我不在Powershell中工作,也不需要涉及Powershell或VBScript的解决方案
在C#/ASP.Net中使用其他编程方式也将受到高度赞赏
编辑:
GetSiteIdFromSiteName
代码可能如下所示:
public static int GetSiteIdFromSiteName(String ServerName, String WebsiteName)
{
ConnectionOptions options = SetUpAuthorization();
ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", ServerName), options);
scope.Connect();
ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IIsSetting");
ManagementObjectSearcher WebSiteFinder = new ManagementObjectSearcher(scope, OQuery);
ArrayList WebSiteListArray = new ArrayList();
ManagementObjectCollection WebSitesCollection = WebSiteFinder.Get();
String WebSiteName = String.Empty;
foreach (ManagementObject WebSite in WebSitesCollection)
{
WebSiteName = WebSite.Properties["Name"].Value.ToString();
WebsiteName = WebSiteName.Replace("W3SVC/", "");
String extrctedSiteId = WebsiteName.Substring(0, WebsiteName.IndexOf('/'));
break;
}
return extrctedSiteId;
}
及
设置授权()
下面是SetupAuthorization函数
public ConnectionOptions SetUpAuthorization()
{
ConnectionOptions options = new ConnectionOptions();
//options.Authentication = AuthenticationLevel.Connect;
//may need to set Packetprivacy enum
options.Authentication = AuthenticationLevel.PacketPrivacy;
options.EnablePrivileges = true;
options.Impersonation = ImpersonationLevel.Impersonate;
return options;
}
关于您看过Web部署工具吗
能够打包ACL、COM、GAC和注册表设置。没关系。我自己买的。 如果目录结构在本地系统上,则需要system.IO.DirectoryInfo。使用远程处理同样可以用于远程服务器 参考资料: 如果WMi必须存在,则Win32_目录是查询中应使用的类:
"Select * from Win32_directory where drive ='"+ DriveLetter +":' and Path ='%" + MyPath + "%'";
参考资料:
谢谢您的回复。我想知道这个工具在某种程度上对我有什么帮助。???我需要在ASP中使用WMI和C#以编程方式获取已部署站点的子文件夹。Net应用程序。我需要找出本地或远程IIS 6.0 Web服务器中现有网站的子文件夹。我不认为我在做任何与这个web部署工具有关的事情。因此,如果您能告诉我…请告诉我…您的目标是.NET的哪个版本?@Steve:BTW,您不应该使用
ArrayList
,除非您被困在.NET 1.1。改为使用List
。我的目标是.Net Framework的v2.0。但是这和我所面临的问题有什么关系吗?上面的代码只是我正在做的类似事情的一个示例,为了明确目的。我已经成功地检索了虚拟目录列表,现在我的目标是检索位于网站物理路径中的实际子文件夹列表。就像网站位于c:\inetpub\wwwroot\中一样,我需要找到此目录路径中的所有子文件夹。。。