How to determine which application pool I am currently using? (IIS6)

I need to know how I can determine the current application pool in which I am running, so I can do it with software.

Does anyone know how to do this for IIS6?

My current code to recycle the application:

/// <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); } 
+4
source share
2 answers

And after searching, I myself found the answer:

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

Hm. They need a way to let me ask my own answer as an answer.

+7
source

I found this too, and it worked for me. Note that you may need to include a link for 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(); } 
+2
source

All Articles