【问题标题】:Restarting IIS application pool based on directory基于目录重启 IIS 应用程序池
【发布时间】:2016-02-02 11:11:45
【问题描述】:

我的项目快完成了,但我似乎无法完成最后一部分:

  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) 带回?

谢谢。

【问题讨论】:

  • 感谢您提供的链接,但是我已经更改了我的问题(最后一段),它应该为您指明我正在寻找的方向。

标签: c# iis


【解决方案1】:

可以试试这个

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

【讨论】:

  • 嗨 Partho,谢谢你,但是我刚刚在 MSDN 上查看了一下,我似乎无法确定“APPLICATION_POOL_URL”是实际的网址还是它绑定的目录to,你能告诉我是哪一个吗?谢谢。
  • 网址如:“IIS://localhost/W3SVC/AppPools”
  • 我还发现我无法“回收”某些池,除非我停止/启动/回收,我想知道是否可能是在 .invoke 上引发 com 错误的池没有t 开始......它也可以在不使用 .Invoke 的 2 参数版本的情况下正常工作
猜你喜欢
  • 2012-03-28
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多