简体   繁体   English

重新启动基于目录的IIS应用程序池

[英]Restarting IIS application pool based on directory

Nearly finished with my project, however I can't seem to be able to get the final section working: 我的项目几乎完成了,但是我似乎无法使最后一节工作:

  1. Fetch all Application Pools on the server. 获取服务器上的所有应用程序池。
  2. Loop through all directories of the application pools until I find a match. 遍历应用程序池的所有目录,直到找到匹配项。
  3. Restart the matching application pool. 重新启动匹配的应用程序池。

That's all I'm trying to do, however I can't get it working. 这就是我要尝试的全部,但是我无法使其正常运行。 The code I have managed to drag together so far, only returns a list of the application pool names: 到目前为止,我设法将其拖在一起的代码仅返回应用程序池名称的列表:

    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();
    }

How would I need to change the above code to also bring me back the directories associated with each of the application pools (C:\\inetpub\\Website1)? 我将如何更改上面的代码,同时还带回与每个应用程序池(C:\\ inetpub \\ Website1)相关联的目录?

Thank you. 谢谢。

Can try this one 可以试试这个

 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);

Basically you have to call directoryEntry.Invoke("Stop/Start/Recycle", null); 基本上,您必须调用directoryEntry.Invoke("Stop/Start/Recycle", null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM