I need to know how I can detect the current application pool I am running under, so I can do a Recycle on it programmatically.
我需要知道如何检测我正在运行的当前应用程序池,因此我可以通过编程方式对其进行回收。
Does anyone know how to do this for IIS6?
有谁知道如何为IIS6做这个?
My current code for recycling the app-pool is:
我目前用于回收应用程序池的代码是:
/// <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);
}
2 个解决方案
#1
7
And after searching I found the answer myself:
搜索后我自己找到了答案:
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;
}
Hmm. They need a way to let me set my own answer as THE answer.
嗯。他们需要一种方法让我自己的答案作为答案。
#2
2
I found this one as well and it worked for me. Note you might need to include a reference for using System.DirectoryServices
;
我也找到了这个,它对我有用。请注意,您可能需要包含使用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();
}
#1
7
And after searching I found the answer myself:
搜索后我自己找到了答案:
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;
}
Hmm. They need a way to let me set my own answer as THE answer.
嗯。他们需要一种方法让我自己的答案作为答案。
#2
2
I found this one as well and it worked for me. Note you might need to include a reference for using System.DirectoryServices
;
我也找到了这个,它对我有用。请注意,您可能需要包含使用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();
}