C# 如何检测我当前运行的应用程序池?(IIS6)
我需要知道如何检测当前运行的应用程序池,以便以编程方式对其进行回收 有人知道如何为IIS6做到这一点吗 我当前用于回收应用程序池的代码是:C# 如何检测我当前运行的应用程序池?(IIS6),c#,iis-6,application-pool,C#,Iis 6,Application Pool,我需要知道如何检测当前运行的应用程序池,以便以编程方式对其进行回收 有人知道如何为IIS6做到这一点吗 我当前用于回收应用程序池的代码是: /// <summary> /// Recycle an application pool /// </summary> /// <param name="IIsApplicationPool"></param> public static void RecycleApp
/// <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);
}
//
///回收应用程序池
///
///
公共静态void RecycleAppPool(字符串IIsApplicationPool){
ManagementScope=new ManagementScope(@“\\localhost\root\MicrosoftIISv2”);
scope.Connect();
ManagementObject appPool=新管理对象(范围,新管理路径(“IIsApplicationPool.Name='W3SVC/AppPools/“+IIsApplicationPool+”),null);
InvokeMethod(“循环”,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;
}
嗯。他们需要一种方法让我把自己的答案设置为答案。我也找到了这个答案,它对我很有用。注意:您可能需要包括使用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();
}