Export (0) Print
Expand All

ApplicationPool Class

IIS 7.0

Provides methods and properties to configure and manage IIS 7 application pools.

Namespace:  Microsoft.Web.Administration
Assembly:  Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)

public sealed class ApplicationPool : ConfigurationElement

The ApplicationPool type exposes the following members.

  NameDescription
Public propertyAttributesGets a configuration attribute collection that contains the list of attributes for this element. (Inherited from ConfigurationElement.)
Public propertyAutoStartGets or sets a value indicating whether the current application pool starts automatically when IIS starts.
Public propertyChildElementsGets all the child elements of the current element. (Inherited from ConfigurationElement.)
Public propertyCpuGets CPU usage parameters for the current application pool.
Public propertyElementTagNameGets the XML tag name of the current element. (Inherited from ConfigurationElement.)
Public propertyEnable32BitAppOnWin64Gets or sets a value indicating whether to allow 32-bit applications to run on a computer that has a 64-bit processor.
Public propertyFailureGets actions to take when the current application pool fails.
Public propertyIsLocallyStoredGets a value indicating whether the configuration element is stored in a particular configuration file. (Inherited from ConfigurationElement.)
Public propertyItemGets or sets an attribute with the specified name. (Inherited from ConfigurationElement.)
Public propertyManagedPipelineModeGets or sets a value that indicates the pipeline mode of managed applications in the current application pool.
Public propertyManagedRuntimeVersionGets or sets the version of the .NET Framework that is used for managed applications in the current application pool.
Public propertyMethodsGets a collection of methods for the configuration element. (Inherited from ConfigurationElement.)
Public propertyNameGets or sets the name of the current application pool.
Public propertyProcessModelGets the process management attributes for the current application pool.
Public propertyQueueLengthGets or sets the maximum number of requests to queue in an application pool before rejecting requests.
Public propertyRawAttributesGets the raw attribute names and values for the current configuration element. (Inherited from ConfigurationElement.)
Public propertyRecyclingGets recycling settings for the current application pool.
Public propertySchemaGets the schema for the current element. (Inherited from ConfigurationElement.)
Public propertyStateGets the run-time state of the current application pool.
Public propertyWorkerProcessesGets the collection of worker processes that service the current application pool.
Top

  NameDescription
Public methodDelete (Inherited from ConfigurationElement.)
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetAttributeReturns a ConfigurationAttribute object that represents the requested attribute. (Inherited from ConfigurationElement.)
Public methodGetAttributeValueReturns the value of the specified attribute. (Inherited from ConfigurationElement.)
Public methodGetChildElement(String)Returns a child element that is under the current configuration element and has the specified name. (Inherited from ConfigurationElement.)
Public methodGetChildElement(String, Type)Returns a child element that is under the current configuration element and has the specified name and type. (Inherited from ConfigurationElement.)
Public methodGetCollection()()()()Returns the default collection for the current configuration element. (Inherited from ConfigurationElement.)
Public methodGetCollection(String)Returns all configuration elements that belong to the current configuration element. (Inherited from ConfigurationElement.)
Public methodGetCollection(Type)Returns the configuration element that has the specified type and is under the current configuration element. (Inherited from ConfigurationElement.)
Public methodGetCollection(String, Type)Returns the configuration element that has the specified name and type and is under the current configuration element. (Inherited from ConfigurationElement.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetMetadataReturns metadata values from the element schema. (Inherited from ConfigurationElement.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRecycleRecycles the current application pool.
Public methodSetAttributeValueSets the value of the specified attribute. (Inherited from ConfigurationElement.)
Public methodSetMetadataSets metadata values from the element schema. (Inherited from ConfigurationElement.)
Public methodStartStarts the current application pool.
Public methodStopStops the current application pool.
Public methodToString (Inherited from Object.)
Top

This class provides configuration and management functionality for application pools. Properties of this class generally correspond directly to the attributes of the applicationPools configuration element in the IIS 7 configuration system.

Application pools are associated with worker processes, contain one or more applications, and provide isolation among different applications.

The following example implements several of the methods and properties of the ApplicationPool class. This example retrieves the ApplicationPool objects in the service module, modifies the property values of the ApplicationPool objects, places the objects into a property bag, and displays the property values in the page module.

Service module:

// Gets the application pool collection from the server.
[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetApplicationPoolCollection()
{
    // Use an ArrayList to transfer objects to the client.
    ArrayList arrayOfApplicationBags = new ArrayList();

    ServerManager serverManager = new ServerManager();
    ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
    foreach (ApplicationPool applicationPool in applicationPoolCollection)
    {
        PropertyBag applicationPoolBag = new PropertyBag();
        applicationPoolBag[ServerManagerDemoGlobals.ApplicationPoolArray] = applicationPool;
        arrayOfApplicationBags.Add(applicationPoolBag);
        // If the applicationPool is stopped, restart it.
        if (applicationPool.State == ObjectState.Stopped)
        {
            applicationPool.Start();
        }
        // Set the CPU limit to a maximum of 25.
        if (applicationPool.Cpu.Limit > 25)
        {
            applicationPool.Cpu.Limit = 25;
        }
        // Set the process model max process to 1 to prohibit Web Garden
        if (applicationPool.ProcessModel.MaxProcesses > 1)
        {
            applicationPool.ProcessModel.MaxProcesses = 1;
        }
        // Set the recycling time to a maximum of one day (1440 minutes).
        if (applicationPool.Recycling.PeriodicRestart.Time.TotalMinutes > 1440)
        {
            applicationPool.Recycling.PeriodicRestart.Time = TimeSpan.FromMinutes(1440);
        }
    }

    // CommitChanges to persist the changes to the ApplicationHost.config.
    serverManager.CommitChanges();
    return arrayOfApplicationBags;
}


Page module:

// Get the ApplicationPool collection
ArrayList applicationPoolCollectionArray = _serviceProxy.GetApplicationPoolCollection();
string applicationdisplay = null;
applicationdisplay = "\nThere are " +
    applicationPoolCollectionArray.Count.ToString() + " applicationPools.\n";
foreach (PropertyBag bag in applicationPoolCollectionArray)
{
    ApplicationPool applicationPool = (ApplicationPool)bag[ServerManagerDemoGlobals.ApplicationPoolArray];
    applicationdisplay += "  " + applicationPool.Name + ":\n";
    applicationdisplay += "    FrameworkVersion - " + applicationPool.ManagedRuntimeVersion + "\n";
    applicationdisplay += "    State: " + applicationPool.State + "\n";
    applicationdisplay += "    WorkerProcesses: " + applicationPool.WorkerProcesses.Count + "\n";
    foreach (WorkerProcess workerProcess in applicationPool.WorkerProcesses)
    {
        applicationdisplay += "       " + workerProcess.ToString() + "\n";
    }
    applicationdisplay += "    CPU limit: " + applicationPool.Cpu.Limit.ToString() + "\n";
    applicationdisplay += "    MaxProcesses: " + applicationPool.ProcessModel.MaxProcesses.ToString() + "\n";
    applicationdisplay += "    Restart time: " + applicationPool.Recycling.PeriodicRestart.Time.TotalMinutes + "\n\n";
}


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft