FTP 服务器运行时 <serverRuntime>
概述
<serverRuntime>
元素配置以下与 Internet Information Services (IIS) 7 服务器运行时相关的设置:
将 enabled 的属性设置为 true 会将 IIS 7 配置为在配置了
<serverRuntime>
元素的 URL 中提供内容;将 enabled 的属性设置为 false 会将 IIS 7 配置为不为该 URL 提供内容。alternateHostName 属性指定与 HTTP 内容位置标头中的计算机名称不同的主机名。
appConcurrentRequestLimit 属性指定可为应用程序排队的最大并发请求数。
enableNagling 属性可启用或禁用 nagling,这是对 HTTP over TCP 的优化措施,可尝试尽量减少发送数据之前所需的数据包数量,从而提高效率。 它的工作原理是等待发送数据包,直到其数据区域已满、200 毫秒的超时期限已过,或者发送方指示已完成发送数据。 IIS 版本 5.1 及更低版本对发送到客户端的所有数据使用 nagling。
注意
Nagling 有一个可能的缺点:如果扩展未填满数据包,则发送响应之前仍有 200 毫秒的延迟。 在对客户端的响应中使用支持 HTTP keep-alive 标头的 ISAPI 扩展时,这种行为最常见。 在这种情况下,IIS 在响应后不会关闭连接,因此最终数据包会等待 200 毫秒。
IIS 7 会检查两个属性的状态,以确定特定 URL 的流量级别。 frequentHitThreshold 属性配置请求数,而 frequentHitTimePeriod 属性配置在判断为频繁命中 URL 之前允许的时间长度。 当编写使用此信息进行处理的 HTTP 模块时,将使用此信息。 有关详细信息,请参阅 IHttpUrlInfo::IsFrequentlyHit 方法一文。
maxRequestEntityAllowed 属性配置请求实体正文中允许的最大字节数限制,uploadReadAheadSize 属性配置 Web 服务器将读取到缓冲区并传递给 ISAPI 扩展的字节数限制。 应考虑增加这些值,因为最终用户可以上传更多内容,这些内容可能会影响 IIS 运行时内存资源。 建议将这些值保持在与应用需求一致的数值,仅在极端情况下使用最大值。
IIS 7.5 中的新增功能
IIS 7.5 为 <serverRuntime>
元素增加了 authenticatedUserOverride 属性,该属性配置 IIS 7 服务器运行时在 IHttpUser::GetPrimaryToken 和 IHttpUser::GetImpersonationToken 方法中提供经过身份验证的用户的标识还是提供工作进程标识。 此属性可以设置为 UseAuthenticatedUser 或 UseWorkerProcessUser,分别指定 IIS 7 服务器运行时是为使用模拟的任何模块提供经过身份验证的用户标识,还是提供工作进程标识。
兼容性
版本 | 说明 |
---|---|
IIS 10.0 | <serverRuntime> 元素在 IIS 10.0 中未进行修改。 |
IIS 8.5 | <serverRuntime> 元素在 IIS 8.5 中未进行修改。 |
IIS 8.0 | <serverRuntime> 元素在 IIS 8.0 中未进行修改。 |
IIS 7.5 | 在 IIS 7.5 中增加了 authenticatedUserOverride 属性。 |
IIS 7.0 | <serverRuntime> 元素是在 IIS 7.0 中引入的。 |
IIS 6.0 | <serverRuntime> 元素替换以下 IIS 6.0 元数据库属性:
|
安装
<serverRuntime>
元素包含在 IIS 7 的默认安装中。
操作方式
IIS 7 中没有用于配置 <serverRuntime>
元素的用户界面。 若要通过示例来了解如何以编程方式配置 <serverRuntime>
元素,请参阅本文档的代码示例部分。
配置
特性
属性 | 说明 | ||||||
---|---|---|---|---|---|---|---|
alternateHostName |
可选的字符串属性。 指定要用于重定向的主机名。 |
||||||
appConcurrentRequestLimit |
可选 uint 属性。 指定可为应用程序排队的最大请求数。 默认值为 5000 。 |
||||||
authenticatedUserOverride |
可选 enum 属性。 指定 IIS 7 服务器运行时是为使用模拟的模块提供经过身份验证的用户标识还是提供工作进程标识。 注:IIS 7.5 中添加了此属性。
UseAuthenticatedUser 。 |
||||||
enabled |
可选的 Boolean 属性。 指定 Web 服务器上的应用程序是能够提供内容 (true) 还是不能提供内容 (false)。 默认值为 true 。 |
||||||
enableNagling |
可选的 Boolean 属性。 指定是启用 (true) 还是禁用 (false) nagling。 默认值为 false 。 |
||||||
frequentHitThreshold |
可选 uint 属性。 指定在 frequentHitTimePeriod 属性中指定的时间范围内必须请求 URL 的次数,达到该次数便被视为频繁命中。 该值必须介于 1 和 2147483647 之间。 默认值为 2 。 |
||||||
frequentHitTimePeriod |
可选的 timeSpan 属性。 指定一个时间间隔,在该时间间隔内,必须按 frequentHitThreshold 属性中指定的次数请求 URL,才能将其视为频繁命中。 默认值为 00:00:10 (10 秒)。 |
||||||
maxRequestEntityAllowed |
可选 uint 属性。 指定请求的实体正文中可以包含的最大字节数。 如果 Content-Length 标头指定更大的数字,IIS 将发送 HTTP 403 错误响应。 默认值为 4294967295 (无限制)。 |
||||||
uploadReadAheadSize |
可选 uint 属性。 指定 Web 服务器将读取到缓冲区并传递给 ISAPI 扩展或模块的字节数。 每个客户端请求会发生这种情况一次。 ISAPI 扩展直接从客户端接收任何其他数据。 该值必须介于 0 和 2147483647 之间。 默认值为 49152 。 |
子元素
无。
配置示例
以下配置示例将 <serverRuntime>
元素的 enable 属性设置为 true,然后通过将 frequentHitThreshold 属性设置为 5 个请求并将 frequentHitTimePeriod 属性设置为 20 秒,以此来配置将被视为“频繁命中”的 URL 的请求数。
<location path="Default Web Site">
<system.webServer>
<serverRuntime enabled="true"
frequentHitThreshold="5"
frequentHitTimePeriod="00:00:20" />
</system.webServer>
</location>
代码示例
以下代码示例将 <serverRuntime>
元素的 enable 属性设置为 true,然后通过将 frequentHitThreshold 属性设置为 5 个请求并将 frequentHitTimePeriod 属性设置为 20 秒,以此来配置将被视为“频繁命中”的 URL 的请求数。
AppCmd.exe
appcmd.exe set config "Default Web Site" -section:system.webServer/serverRuntime /enabled:"True" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/serverRuntime /frequentHitThreshold:"5" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/serverRuntime /frequentHitTimePeriod:"00:00:20" /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 serverRuntimeSection = config.GetSection("system.webServer/serverRuntime", "Default Web Site");
serverRuntimeSection["enabled"] = true;
serverRuntimeSection["frequentHitThreshold"] = 5;
serverRuntimeSection["frequentHitTimePeriod"] = TimeSpan.Parse("00:00:20");
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 serverRuntimeSection As ConfigurationSection = config.GetSection("system.webServer/serverRuntime", "Default Web Site")
serverRuntimeSection("enabled") = True
serverRuntimeSection("frequentHitThreshold") = 5
serverRuntimeSection("frequentHitTimePeriod") = TimeSpan.Parse("00:00:20")
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var serverRuntimeSection = adminManager.GetAdminSection("system.webServer/serverRuntime", "MACHINE/WEBROOT/APPHOST/Default Web Site");
serverRuntimeSection.Properties.Item("enabled").Value = true;
serverRuntimeSection.Properties.Item("frequentHitThreshold").Value = 5;
serverRuntimeSection.Properties.Item("frequentHitTimePeriod").Value = "00:00:20";
adminManager.CommitChanges();
VBScript
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set serverRuntimeSection = adminManager.GetAdminSection("system.webServer/serverRuntime", "MACHINE/WEBROOT/APPHOST/Default Web Site")
serverRuntimeSection.Properties.Item("enabled").Value = True
serverRuntimeSection.Properties.Item("frequentHitThreshold").Value = 5
serverRuntimeSection.Properties.Item("frequentHitTimePeriod").Value = "00:00:20"
adminManager.CommitChanges()