概述
在 IIS 7 及更高版本上创建新的应用程序池时,至少必须为应用程序池分配一个唯一名称。 根据使用应用程序池的应用程序的需要配置所有其他属性。
IIS 7.5 及更高版本中的新增功能
从 IIS 7.5 开始,可以使用
IIS 7.5 及更高版本还为
兼容性
版本
说明
IIS 10.0
IIS 8.5
IIS 8.0
managedRuntimeVersion 属性的默认值已更改为 "",v4.0 已添加为 managedRuntimeVersion 的值。
IIS 7.5
IIS 7.5 更新了
IIS 7.0
IIS 7.0 中引入了
IIS 6.0
安装
在 IIS 7 及更高版本的默认安装中包含
操作方式
如何创建新应用程序池
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows 8 或 Windows 8.1:
按住 Windows 徽标键,按字母 X,然后单击“控制面板”。
单击“管理工具”,然后双击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
在任务栏上,单击“开始”,然后单击“控制面板”。
双击“管理工具”,然后双击“Internet Information Services (IIS)管理器”。
在“连接”窗格中,展开服务器名称,然后单击“应用程序池”。
在“操作”窗格中,单击“添加应用程序池...”。
在“添加应用程序池”对话框中,在“名称:”框中输入应用程序池的名称,在“.NET Framework 版本:”下拉列表中选择站点或应用程序使用的 .NET Framework 版本,在“托管管道模式:”下拉列表中选择“集成”或“经典”,然后单击“确定”。
如何为现有站点或应用程序配置应用程序池
在“连接”窗格中,展开“站点”,然后导航到要添加到应用程序池的网站或应用程序。
在“操作”窗格中,单击“高级设置...”
在“高级设置”对话框的“常规”部分,单击“应用程序池”条目,然后单击省略号按钮。
在“选择应用程序池”对话框中,从“应用程序池:”下拉列表框中选择应用程序池,单击“确定”,然后再次单击“确定”。
配置
特性
属性
说明
autoStart
可选布尔属性。如果为 true,向 World Wide Web 发布服务 (W3SVC) 指示应用程序池在创建时或 IIS 启动时应自动启动。默认值为 true。
CLRConfigFile
可选字符串值。指定应用程序池的 .NET 配置文件。注意:IIS 7.5 中添加了此属性。没有默认值。
enable32BitAppOnWin64
可选布尔属性。如果为 True,则支持 32 位应用程序在运行 64 位 Windows 版本的计算机上运行。默认值为 false。
enableConfigurationOverride
可选布尔属性。如果为 true,则指示将为此应用程序池中的应用程序处理 Web.config 文件中的委派设置。 如果为 false,则此应用程序池将忽略 Web.config 文件中的所有设置。默认值为 true。
managedPipelineMode
可选的枚举属性。指定用于处理托管内容请求的请求处理模式。managedPipelineMode 属性可以是下列可能的值之一。 值 说明 Classic 指定应用程序池使用单独的 IIS 和 ASP.NET 请求处理管道,这适用于 ASP.NET 1.1 应用程序以及在集成模式下不起作用的 ASP.NET 2.0 或更高版本的应用程序。数值为 1。 Integrated 指定应用程序池使用集成的 IIS 和 ASP.NET 请求处理管道,这仅适用于 ASP.NET 2.0 或更高版本的应用程序。数值为 0。 默认为 Integrated。
managedRuntimeLoader
可选的字符串属性。指定要用于预加载应用程序池的托管加载程序。注意:IIS 7.5 中添加了此属性。默认值为 webengine4.dll。
managedRuntimeVersion
可选的字符串属性。指定应用程序池使用的 CLR 版本。managedRuntimeVersion 属性可以是以下可能的值之一。 值 说明 v1.1 指定应用程序池使用 CLR 版本 1.1。 v2.0 指定应用程序池使用 CLR 版本 2.0,可以是 .NET Framework 版本 2.0、3.0 或 3.5。 v4.0 指定应用程序池使用 CLR 版本 4.0,可以是 .NET Framework 版本 4.0 或 4.5。默认值为 ""。
name
必需的字符串属性。为服务器上的应用程序池指定一个唯一名称。
passAnonymousToken
可选布尔属性。如果为 true,则 Windows Process Activation Service (WAS) 会为内置 IUSR 匿名用户帐户创建令牌并将其传递到匿名身份验证模块。 匿名身份验证模块使用该令牌模拟内置帐户。 如果 PassAnonymousToken 为 false,则不会传递令牌。注意:IUSR 匿名用户帐户替代了 IIS_MachineName 匿名帐户。 IUSR 帐户可由 IIS 或其他应用程序使用。 在设置过程中,不会为其分配任何权限。默认值为 true。
queueLength
可选 uint 属性。向 HTTP.sys 指示在拒绝未来的请求之前要在应用程序池中排队的请求数量。 默认值为 1000。如果超出为此属性设置的值,IIS 会拒绝后续请求并显示 503 错误。 如果 loadBalancerCapabilities 设置为 true,则连接将关闭,而不是拒绝请求并指示 503 错误。 有关 loadBalancerCapabilities 的详细信息,请参阅应用程序池的故障设置。
startMode
可选的枚举值。指定应用程序池的启动类型。注意:IIS 7.5 中添加了此属性。startMode 属性可以是以下可能值之一。 值 说明 AlwaysRunning 指定 Windows Process Activation Service (WAS) 将始终启动应用程序池。 此行为允许应用程序在处理任何 HTTP 请求之前加载操作环境,从而减少了对应用程序初始 HTTP 请求的启动处理。数值为 1。 OnDemand 指定当对应用程序池中托管的应用程序发出 HTTP 请求时,Windows Process Activation Service (WAS) 将启动应用程序池。 此行为类似于早期版本的 IIS 中的 WAS 行为。数值为 0。 默认值为 OnDemand。
子元素
元素
说明
cpu
配置 CPU 相关性和 CPU 操作。
environmentVariables
配置一个要传递给工作进程的环境变量集合。
failure
配置在应用程序池失败时要执行的操作。
processModel
配置应用程序池的进程管理属性。
recycling
配置应用程序池回收。
配置示例
以下配置示例使用应用程序池
代码示例
下面的代码示例将名为 Contoso 的应用程序池添加到 IIS 7 及更高版本的服务器中,然后将应用程序池设置为每天在凌晨 3:00 回收。
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='Contoso']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='Contoso'].recycling.periodicRestart.schedule.[value='03:00:00']" /commit:apphost
还可以使用以下语法:
appcmd.exe add apppool /name:"Contoso"
appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='Contoso'].recycling.periodicRestart.schedule.[value='03:00:00']" /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");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
ConfigurationElement addElement = applicationPoolsCollection.CreateElement("add");
addElement["name"] = @"Contoso";
ConfigurationElement recyclingElement = addElement.GetChildElement("recycling");
ConfigurationElement periodicRestartElement = recyclingElement.GetChildElement("periodicRestart");
ConfigurationElementCollection scheduleCollection = periodicRestartElement.GetCollection("schedule");
ConfigurationElement addElement1 = scheduleCollection.CreateElement("add");
addElement1["value"] = TimeSpan.Parse("03:00:00");
scheduleCollection.Add(addElement1);
applicationPoolsCollection.Add(addElement);
serverManager.CommitChanges();
}
}
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim applicationPoolsSection As ConfigurationSection = config.GetSection("system.applicationHost/applicationPools")
Dim applicationPoolsCollection As ConfigurationElementCollection = applicationPoolsSection.GetCollection
Dim addElement As ConfigurationElement = applicationPoolsCollection.CreateElement("add")
addElement("name") = "Contoso"
Dim recyclingElement As ConfigurationElement = addElement.GetChildElement("recycling")
Dim periodicRestartElement As ConfigurationElement = recyclingElement.GetChildElement("periodicRestart")
Dim scheduleCollection As ConfigurationElementCollection = periodicRestartElement.GetCollection("schedule")
Dim addElement1 As ConfigurationElement = scheduleCollection.CreateElement("add")
addElement1("value") = TimeSpan.Parse("03:00:00")
scheduleCollection.Add(addElement1)
applicationPoolsCollection.Add(addElement)
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST");
var applicationPoolsCollection = applicationPoolsSection.Collection;
var addElement = applicationPoolsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "Contoso";
var recyclingElement = addElement.ChildElements.Item("recycling");
var periodicRestartElement = recyclingElement.ChildElements.Item("periodicRestart");
var scheduleCollection = periodicRestartElement.ChildElements.Item("schedule").Collection;
var addElement1 = scheduleCollection.CreateNewElement("add");
addElement1.Properties.Item("value").Value = "03:00:00";
scheduleCollection.AddElement(addElement1);
applicationPoolsCollection.AddElement(addElement);
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST")
Set applicationPoolsCollection = applicationPoolsSection.Collection
Set addElement = applicationPoolsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "Contoso"
Set recyclingElement = addElement.ChildElements.Item("recycling")
Set periodicRestartElement = recyclingElement.ChildElements.Item("periodicRestart")
Set scheduleCollection = periodicRestartElement.ChildElements.Item("schedule").Collection
Set addElement1 = scheduleCollection.CreateNewElement("add")
addElement1.Properties.Item("value").Value = "03:00:00"
scheduleCollection.AddElement(addElement1)
applicationPoolsCollection.AddElement(addElement)
adminManager.CommitChanges()