【问题标题】:How to detect what Application Pool I am currently running under? (IIS6)如何检测我当前在哪个应用程序池下运行? (IIS6)
【发布时间】:2010-09-24 21:45:02
【问题描述】:

我需要知道如何检测我正在运行的当前应用程序池,以便以编程方式对其进行回收。

有人知道如何为 IIS6 执行此操作吗?

我当前用于回收应用程序池的代码是:

    /// <summary>
    /// Recycle an application pool
    /// </summary>
    /// <param name="IIsApplicationPool"></param>
    public static void RecycleAppPool(string IIsApplicationPool) {
        ManagementScope scope = new ManagementScope(@"\\localhost\root\MicrosoftIISv2");
        scope.Connect();
        ManagementObject appPool = new ManagementObject(scope, new ManagementPath("IIsApplicationPool.Name='W3SVC/AppPools/" + IIsApplicationPool + "'"), null);

        appPool.InvokeMethod("Recycle", null, null);
    }   

【问题讨论】:

    标签: c# iis-6 application-pool


    【解决方案1】:

    经过搜索,我自己找到了答案:

       public string GetAppPoolName() {
    
            string AppPath = Context.Request.ServerVariables["APPL_MD_PATH"];
    
            AppPath = AppPath.Replace("/LM/", "IIS://localhost/");
            DirectoryEntry root = new DirectoryEntry(AppPath);
            if ((root == null)) {
                return " no object got";
            }
            string AppPoolId = (string)root.Properties["AppPoolId"].Value;
            return AppPoolId;
        }
    

    嗯。他们需要一种方法让我将自己的答案设置为 THE 答案。

    【讨论】:

      【解决方案2】:

      我也找到了这个,它对我有用。请注意,您可能需要包含using System.DirectoryServices 的引用;

          private static string GetCurrentApplicationPoolId()
          {
              string virtualDirPath = AppDomain.CurrentDomain.FriendlyName;
              virtualDirPath = virtualDirPath.Substring(4);
              int index = virtualDirPath.Length + 1;
              index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
              index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
              virtualDirPath = "IIS://localhost/" + virtualDirPath.Remove(index);
              DirectoryEntry virtualDirEntry = new DirectoryEntry(virtualDirPath);
              return virtualDirEntry.Properties["AppPoolId"].Value.ToString();
          }
      

      【讨论】:

        猜你喜欢
        • 2011-04-10
        • 1970-01-01
        • 2011-09-26
        • 2013-09-28
        • 2011-11-18
        • 1970-01-01
        • 2012-09-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多