簡體   English   中英

重新啟動基於目錄的IIS應用程序池

[英]Restarting IIS application pool based on directory

我的項目幾乎完成了,但是我似乎無法使最后一節工作:

  1. 獲取服務器上的所有應用程序池。
  2. 遍歷應用程序池的所有目錄,直到找到匹配項。
  3. 重新啟動匹配的應用程序池。

這就是我要嘗試的全部,但是我無法使其正常運行。 到目前為止,我設法將其拖在一起的代碼僅返回應用程序池名稱的列表:

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM