【发布时间】:2009-03-11 22:04:50
【问题描述】:
如何找出在 C# 中使用的 IIS 虚拟目录的 .NET 框架。我需要向用户展示它。
using System.DirectoryServices;
using System.IO;
private enum IISVersion
{
IIS5,
IIS6
}
private void ReadVirtualDirectory(string server, string directory, IISVersion version)
{
string siteID = string.Empty;
string path = string.Empty;
switch(verison)
{
case IISVersion.IIS5:
path = string.Format("IIS://{0}/W3SVC/1/Root", server);
if(!string.IsNullOrEmpty(directory))
{
path = string.Concat(path, "/", directory);
}
break;
case IISVersion.IIS6:
path = string.Format("IIS://{0}/W3SVC", server);
if(!string.IsNullOrEmpty(directory))
{
DirectoryEntry de = new DirectoryEntry(path);
foreach(DirectoryEntry child in de.Children)
{
if(child.Properties["ServerComment"].Value.ToString().ToLower() == directory)
{
siteID = child.Name;
break;
}
}
path = string.Concat(path, "/", siteID);
de.Close()
de = null;
}
break;
}
DirectoryEntry iis = new DirectoryEntry(path);
//display iis properties here...
//need to display if the virtual directory is running under .NET 1.1 or 2.0
iis.Close();
iis = null;
}
【问题讨论】:
-
不错的代码。它做对了什么?它做错了什么?它没有回答你问的问题吗?如果没有,为什么不呢?
-
你想知道什么.NET框架或什么版本的IIS?
-
我想了解.NET框架。
-
@Kev - 无需回滚。这对我的问题来说是一个更好的标题。
标签: c# asp.net iis directoryservices