[英]Restarting IIS application pool based on directory
我的項目幾乎完成了,但是我似乎無法使最后一節工作:
這就是我要嘗試的全部,但是我無法使其正常運行。 到目前為止,我設法將其拖在一起的代碼僅返回應用程序池名稱的列表:
public static string[] FetchAppPools()
{
List<string> lvAppPools = new List<string>();
DirectoryEntry lvWebService = new DirectoryEntry("IIS://localhost/W3SVC");
IEnumerator ie = lvWebService.Children.GetEnumerator();
DirectoryEntry lvServer = null;
while(ie.MoveNext())
{
lvServer = (DirectoryEntry)ie.Current;
if (lvServer.SchemaClassName == "IIsWebServer")
lvAppPools.Add(lvServer.Properties["ServerComment"][0].ToString());
}
return lvAppPools.ToArray();
}
我將如何更改上面的代碼,同時還帶回與每個應用程序池(C:\\ inetpub \\ Website1)相關聯的目錄?
謝謝。
可以試試這個
var directoryEntry = new DirectoryEntry(APPLICATION_POOL_URL, USERNAME, PASSWORD);
// call to stop the Application Pool
directoryEntry.Invoke("Stop", null);
// call to start the Application Pool
directoryEntry.Invoke("Start", null);
// call to recycle the Application Pool
directoryEntry.Invoke("Recycle", null);
基本上,您必須調用directoryEntry.Invoke("Stop/Start/Recycle", null);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.