4

実行中の現在のアプリケーション プールを検出する方法を知る必要があるため、プログラムでリサイクルを行うことができます。

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

2 に答える 2

7

そして、検索した後、私は自分で答えを見つけました:

   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答えとして設定できるようにする方法を必要としています.

于 2008-12-02T09:38:14.800 に答える
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();
    }
于 2012-09-19T18:40:04.730 に答える