0

Web ロールを使用しました。プロジェクトの開始スクリプトを使用して、パイプライン モードをクラシックに変更できるかどうか疑問に思っています。

C#コードを使用してそれを実現できますが、cmdを使用することを好みます。ここで遭遇する問題は、cmdでapplicationPool名を取得するにはどうすればよいですか? ここに私のC#コードがあります:

    {
        using (ServerManager serverManager = new ServerManager())
        {
            Site site = serverManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"];

                Configuration config = serverManager.GetApplicationHostConfiguration();
                string AppPoolName = site.Applications[0].ApplicationPoolName;

                ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");

                ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();

                ConfigurationElement addElement = FindElement(applicationPoolsCollection, "add", "name", AppPoolName);
                if (addElement == null) throw new InvalidOperationException("Element not found!");

                addElement["managedPipelineMode"] = @"Classic";

                serverManager.CommitChanges();



            return base.OnStart();
        }
    }

    private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
    {
        foreach (ConfigurationElement element in collection)
        {
            if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
            {
                bool matches = true;

                for (int i = 0; i < keyValues.Length; i += 2)
                {
                    object o = element.GetAttributeValue(keyValues[i]);
                    string value = null;
                    if (o != null)
                    {
                        value = o.ToString();
                    }

                    if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
                    {
                        matches = false;
                        break;
                    }
                }
                if (matches)
                {
                    return element;
                }
            }
        }
        return null;
    }

}

どうすればそれができますか?

4

1 に答える 1

0

直面している問題がプール名だけである場合は、appcmd使用可能なすべてのプールを一覧表示するために使用してみてください。

appcmd.exe list apppool /text:*

これにより、IIS で使用可能なすべてのアプリプールがアプリ名とともに提供されます (十分な権限がある場合)。

于 2013-05-06T12:07:47.767 に答える