Csharp/C#教程:如何检测我当前运行的应用程序池? (IIS6)分享


如何检测我当前运行的应用程序池? (IIS6)

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

有谁知道如何为IIS6做这个?

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

///  /// Recycle an application pool ///  ///  public static void RecycleAppPool(string IIsApplicationPool) { ManagementScope scope = new ManagementScope(@"\localhostrootMicrosoftIISv2"); scope.Connect(); ManagementObject appPool = new ManagementObject(scope, new ManagementPath("IIsApplicationPool.Name='W3SVC/AppPools/" + IIsApplicationPool + "'"), null); appPool.InvokeMethod("Recycle", null, null); } 

搜索后我自己找到了答案:

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

嗯。 他们需要一种方法让我自己的答案作为答案。

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

上述就是C#学习教程:如何检测我当前运行的应用程序池? (IIS6)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/986657.html

(0)
上一篇 2021年12月22日
下一篇 2021年12月22日

精彩推荐