简体   繁体   中英

How can I use start script change IIS Application pool pipeline mode

I used a web role. I just wonder if I can use Start script for my project to change the pipeline mode to classic.

I can use C# code achieve that, but I prefer to use cmd, The problem I meet here is how can I get the applicationPool name by cmd? Here is my C# code:

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

}

So How can I do that ?

If the pool name is the only problem you are facing, try using appcmd for listing all available pools:

appcmd.exe list apppool /text:*

This should give you all apppools available on IIS with the app names (provided you have enough rights).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM