我的任务是在C#中创建一个Web应用程序,它获取远程服务器(相同位置)中托管的网站的IIS和应用程序池详细信息。非常感谢任何想法或帮助!!!
-Renji
答案 0 :(得分:1)
这在某种程度上是一个广泛的问题,但为了提供帮助,您可以从以下几点开始:
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
我想这足以让你开始探索与IIS相关的所有内容,希望它有所帮助。
答案 1 :(得分:0)
我也有同样的要求。在做了很多跟踪和错误的方法时,我得到了结果。
public static SortedDictionary<string,string> GetApplicationPoolNames ( string mname = null )
{
try
{
ServerManager manager = new ServerManager ();
SortedDictionary<string,string> ApplicationPoolStatus = new SortedDictionary<string,string> ();
if (string.IsNullOrEmpty (mname))
mname = System.Environment.MachineName;
string appPoolName = string.Empty;
manager = ServerManager.OpenRemote (mname);
ApplicationPoolCollection applicationPoolCollection = manager.ApplicationPools;
foreach (ApplicationPool applicationPool in applicationPoolCollection)
{
if (!string.IsNullOrEmpty (applicationPool.Name))
{
if (!ApplicationPoolStatus.ContainsKey (applicationPool.Name))
{
ApplicationPoolStatus.Add (applicationPool.Name,string.Empty);
}
ApplicationPoolStatus[applicationPool.Name] = applicationPool.State.ToString ();
}
}
return ApplicationPoolStatus;
}
catch (Exception)
{
throw;
}
}
public SortedDictionary<string,string> ShowApplicationPoolDatas ()
{
SortedDictionary<string,string> ApplicationPoolStatus = new SortedDictionary<string,string> ();
var domain = this.HttpContext.Request.Url.Host;
DirectoryEntry Services = new DirectoryEntry ("IIS://"+ domain + "/W3SVC/APPPOOLS");
foreach (DirectoryEntry Entry in Services.Children)
{
if (!string.IsNullOrEmpty (Entry.Name))
{
if (!ApplicationPoolStatus.ContainsKey (Entry.Name))
{
ApplicationPoolStatus.Add (Entry.Name,string.Empty);
}
}
var intStatus = (Int32)Entry.InvokeGet ("AppPoolState");
switch (intStatus)
{
case 2:
ApplicationPoolStatus[Entry.Name] = "Running";
break;
case 4:
ApplicationPoolStatus[Entry.Name] = "Stopped";
break;
default:
ApplicationPoolStatus[Entry.Name] = "Unknown";
break;
}
}
return ApplicationPoolStatus;
}