[英]An Application which fetches IIS and App Pool details of website hosted in remote server
我有一個用C#創建Web應用程序的任務,該應用程序將獲取托管在遠程服務器(相同位置)中的網站的IIS和應用程序池詳細信息。任何想法或幫助都非常感謝!!!
-仁治
從某種程度上來說,這是一個廣泛的問題,但是為了幫助您,請從以下幾點開始:
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName()
我想這足以讓您開始探索與IIS相關的所有內容,希望對您有所幫助。
我也有同樣的要求。 經過這么多的跟蹤和錯誤處理,我得到了結果。
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.