应用程序池默认值 <applicationPoolDefaults>

概述

<applicationPools> 集合的 <applicationPoolDefaults> 集合为 Web 服务器上的所有应用程序池配置默认值。

注意

<applicationPoolDefaults> 集合中未显式定义的任何默认值仍将继承 IIS 7 及更高版本架构中的默认值,且各个应用程序池设置将替代任何默认值。

兼容性

版本 说明
IIS 10.0 <applicationInitialization> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <applicationInitialization> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 已向 IIS 8.0 中的 managedRuntimeVersion 属性添加了另一个值("v4.0"),其默认值更改为 "" 而不是 "v2.0"。
IIS 7.5 <applicationPoolDefaults> 元素未在 IIS 7.5 中进行修改。
IIS 7.0 <applicationPoolDefaults> 元素是在 IIS 7.0 中引入的。
IIS 6.0 <applicationPoolDefaults> 元素替换了 IIS 6.0 IIsApplicationPools 元数据属性的部分内容

安装

在 IIS 7 及更高版本的默认安装中包含 <applicationPools> 集合。

操作方式

如何设置应用程序池默认值

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
  2. 在“连接”窗格中,展开服务器名称,然后单击“应用程序池”

  3. 在“操作”窗格中,单击“设置应用程序池默认值...”
    Screenshot of the Application Pools screen, showing the Filter field.

  4. 在“应用程序池默认值”对话框中,指定需要的选项
    Screenshot of the Application Pool Defaults dialog box.

  5. 指定完设置后,单击“确定”

配置

特性

属性 说明
autoStart 可选布尔属性。

如果为 true,向 World Wide Web 发布服务 (W3SVC) 指示应用程序池在创建时或 IIS 启动时应自动启动

默认值为 true
CLRConfigFile 可选字符串值。

指定应用程序池的 .NET 配置文件。

注:IIS 7.5 中添加了此属性。

没有默认值。
enable32BitAppOnWin64 可选布尔属性。

如果为 True,则支持 32 位应用程序在 64 位版本的 Windows 上运行

默认值为 false
managedPipelineMode 可选的枚举属性。

指定用于处理托管内容请求的请求处理模式。

managedPipelineMode 属性可以是下列可能的值之一;默认值为 Integrated
说明
Classic 指定应用程序池使用单独的 IIS 和 ASP.NET 请求处理管道,这适用于 ASP.NET 1.1 应用程序以及在集成模式下不起作用的 ASP.NET 2.0 应用程序。

数值为 1
Integrated 指定应用程序池使用集成的 IIS 和 ASP.NET 请求处理管道,这仅适用于 ASP.NET 2.0 或更高版本的应用程序。

数值为 0
managedRuntimeLoader 可选的字符串属性。

指定要用于预加载应用程序池的托管加载程序。

注:IIS 7.5 中添加了此属性。

默认值为 webengine4.dll
managedRuntimeVersion 可选的字符串属性。

指定要由应用程序池使用的 .NET Framework 版本。

managedRuntimeVersion 属性可以是以下可能的值之一;默认值为 ""
说明
v1.1 指定应用程序池使用 .NET Framework 版本 1.1。
v2.0 指定应用程序池使用 .NET Framework 版本 2.0。
v4.0 指定应用程序池使用 .NET Framework 版本 4.0。
name 必需的字符串属性。

为服务器上的应用程序池指定一个唯一名称。
queueLength 可选 uint 属性。

向 HTTP.sys 指示在拒绝未来的请求之前有多少个请求要在应用程序池中排队。

如果超出为此属性设置的值,IIS 会拒绝后续请求并显示 503 错误。 如果 loadBalancerCapabilities 设置为 true,则连接将关闭,而不是拒绝请求并指示 503 错误。 有关 loadBalancerCapabilities 的详细信息,请参阅应用程序池的故障设置

默认值为 1000
startMode 可选的枚举值。

指定应用程序池的启动类型。

注:IIS 7.5 中添加了此属性。

startMode 属性可以是下列可能的值之一;默认值为 OnDemand
说明
AlwaysRunning 指定 Windows Process Activation Service (WAS) 将始终启动应用程序池。 此行为允许应用程序在处理任何 HTTP 请求之前加载操作环境,从而减少应用程序初始 HTTP 请求的启动处理。

数值为 1
OnDemand 指定当对应用程序池中托管的应用程序发出 HTTP 请求时,Windows Process Activation Service (WAS) 将启动应用程序池。 此行为类似于早期版本的 IIS 中的 WAS 行为。

数值为 0

子元素

元素 说明
cpu 配置 CPU 相关性和 CPU 操作。
environmentVariables 配置一个要传递给工作进程的环境变量集合。
failure 配置在应用程序池失败时要执行的操作。
processModel 配置应用程序池的进程管理属性。
recycling 配置应用程序池回收。

配置示例

以下配置示例指定要作为内置应用程序池标识的所有应用程序池的默认标识,并指定回收应用程序池后的默认请求数为 200。

<applicationPools>
   <add name="DefaultAppPool" />
   <applicationPoolDefaults>
      <processModel identityType="ApplicationPoolIdentity" />
      <recycling>
         <periodicRestart requests="200" />
      </recycling>
   </applicationPoolDefaults>
</applicationPools>

代码示例

以下示例将应用程序池配置为自动启动,以使用 .NET 环境的 2.0 版本,并默认使用集成管道。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.autoStart:"True" /commit:apphost

appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.managedRuntimeVersion:"v2.0" /commit:apphost

appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.managedPipelineMode:"Integrated" /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {

   private static void Main() {

      using(ServerManager serverManager = new ServerManager()) { 
         Configuration config = serverManager.GetApplicationHostConfiguration();

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

         ConfigurationElement applicationPoolDefaultsElement = applicationPoolsSection.GetChildElement("applicationPoolDefaults");
         applicationPoolDefaultsElement["autoStart"] = true;
         applicationPoolDefaultsElement["managedRuntimeVersion"] = @"v2.0";
         applicationPoolDefaultsElement["managedPipelineMode"] = @"Integrated";

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Class Sample
   Shared Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim applicationPoolsSection As ConfigurationSection = config.GetSection("system.applicationHost/applicationPools")
      Dim applicationPoolDefaultsElement As ConfigurationElement = applicationPoolsSection.GetChildElement("applicationPoolDefaults")
      applicationPoolDefaultsElement("autoStart") = True
      applicationPoolDefaultsElement("managedRuntimeVersion") = "v2.0"
      applicationPoolDefaultsElement("managedPipelineMode") = "Integrated"
      serverManager.CommitChanges()
   End Sub
End Class

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST");
var applicationPoolDefaultsElement = applicationPoolsSection.ChildElements.Item("applicationPoolDefaults");
applicationPoolDefaultsElement.Properties.Item("autoStart").Value = true;
applicationPoolDefaultsElement.Properties.Item("managedRuntimeVersion").Value = "v2.0";
applicationPoolDefaultsElement.Properties.Item("managedPipelineMode").Value = "Integrated";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST")
Set applicationPoolDefaultsElement = applicationPoolsSection.ChildElements.Item("applicationPoolDefaults")
applicationPoolDefaultsElement.Properties.Item("autoStart").Value = True
applicationPoolDefaultsElement.Properties.Item("managedRuntimeVersion").Value = "v2.0"
applicationPoolDefaultsElement.Properties.Item("managedPipelineMode").Value = "Integrated"

adminManager.CommitChanges()