共用方式為


伺服器執行時間 < 伺服器Runtime>

概觀

元素 <serverRuntime> 會設定下列與 Internet Information Services (IIS) 7 伺服器執行時間相關的設定:

  • enabled 屬性設定為 true 會將 IIS 7 設定為在設定元素的 <serverRuntime> URL 上提供內容;將 enabled 屬性設定為 false 會將 IIS 7 設定為不提供該 URL 的內容。

  • alternateHostName屬性會指定與 HTTP Content-location 標頭中的電腦名稱稱不同的主機名稱。

  • appConcurrentRequestLimit屬性會指定可針對應用程式排入佇列的並行要求數目上限。

  • enableNagling屬性會啟用或停用流覽,這是透過 TCP 的 HTTP 優化,藉由嘗試將傳送資料之前所需的封包數目降至最低,以提升效率。 其運作方式是等候傳送封包直到其資料區域已滿、直到 200 毫秒逾時期間到期,或直到傳送者指出它已完成傳送資料為止。 IIS 5.1 版和更早版本會針對傳送至用戶端的所有資料使用流覽。

    注意

    Nagling 有可能的缺點;如果延伸模組未填滿封包,在傳送回應之前仍有 200 毫秒的延遲。 當您在對用戶端的回應中使用支援 HTTP keep-alive 標頭的 ISAPI 擴充功能時,最常看到此行為。 在此情況下,IIS 不會在回應之後關閉連線,因此最終封包最後會等候 200 毫秒。

  • IIS 7 會檢查兩個屬性的狀態,以判斷特定 URL 的流量層級。 frequentHitThreshold屬性會設定要求數目,而 frequentHitTimePeriod屬性會設定該 URL 判斷為經常叫用之前所允許的時間量。 撰寫使用此資訊來處理的 HTTP 模組時,會使用這項資訊。 如需詳細資訊,請參閱 IHttpUrlInfo::IsFrequentlyHit 方法 一文。

  • maxRequestEntityAlloweduploadReadAheadSize屬性分別設定要求實體主體中允許的最大位元組數目限制,以及 Web 服務器將讀取到緩衝區中的位元組數目,並傳遞至 ISAPI 擴充功能。 請注意,增加這些值可讓使用者上傳更多內容,這可能會影響 IIS 執行時間記憶體資源。 建議將這些值保持在與應用程式需求一致的數位,而且只有在極端情況下才會使用最大值。

IIS 7.5 的新功能

IIS 7.5 已將 authenticatedUserOverride 屬性新增至 <serverRuntime> 元素,以設定 IIS 7 伺服器執行時間是否會在 IHttpUser::GetPrimaryTokenIHttpUser::GetImpersonationToken 方法中提供已驗證使用者的身分識別或背景工作進程識別。 這個屬性可以設定為 UseAuthenticatedUserUseWorkerProcessUser,而且這些值分別指定 IIS 7 伺服器執行時間是否會針對任何使用模擬的模組提供已驗證使用者的身分識別或背景工作進程識別。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <serverRuntime>
IIS 8.5 未在 IIS 8.5 中修改專案 <serverRuntime>
IIS 8.0 未在 IIS 8.0 中修改專案 <serverRuntime>
IIS 7.5 authenticatedUserOverride屬性已在 IIS 7.5 中新增。
IIS 7.0 元素 <serverRuntime> 是在 IIS 7.0 中引進。
IIS 6.0 元素 <serverRuntime> 會取代下列 IIS 6.0 中繼基底屬性:
  • SetHostName
  • MaxRequestEntityAllowed
  • UploadReadAheadSize

安裝程式

元素 <serverRuntime> 包含在 IIS 7 的預設安裝中。

作法

沒有使用者介面可讓您 <serverRuntime> 設定 IIS 7 的 元素。 For examples of how to configure the <serverRuntime> element programmatically, see the Code Samples section of this document.

組態

屬性

屬性 描述
alternateHostName 選擇性字串屬性。

指定要用於重新導向的主機名稱。
appConcurrentRequestLimit 選擇性 uint 屬性。

指定可針對應用程式排入佇列的要求數目上限。

預設值是 5000
authenticatedUserOverride 選擇性列舉屬性。

指定 IIS 7 伺服器執行時間是否會為使用模擬的模組提供已驗證使用者的身分識別或背景工作進程識別。

注意: 這個屬性已在 IIS 7.5 中新增。
描述
UseAuthenticatedUser 指定 IIS 會提供已驗證使用者的權杖;在此內容中執行的應用程式將受限於已驗證使用者身分識別的任何存取限制。

數值為 1
UseWorkerProcessUser 指定 IIS 會提供背景工作進程身分識別的權杖,而不是使用已驗證使用者的身分識別;在此內容中執行的應用程式將受限於背景工作進程身分識別的任何存取限制。

數值為 2
預設值是 UseAuthenticatedUser
enabled 選擇性 Boolean 屬性。

指定 Web 服務器上的應用程式是否能夠提供內容 (true) 或無法提供 內容 (false) 。

預設值是 true
enableNagling 選擇性 Boolean 屬性。

指定 (true) 或停用 (false) 啟用 Nagling。

預設值是 false
frequentHitThreshold 選擇性 uint 屬性。

指定必須在 frequentHitTimePeriod 屬性中指定的時間範圍內要求 URL 的次數,以視為經常叫用。 此值必須介於 1 和 2147483647之間。

預設值是 2
frequentHitTimePeriod 選擇性的 timeSpan 屬性。

指定 URL 在被視為經常叫用之前,必須要求 URL 在 frequentHitThreshold 屬性中指定的次數的時間間隔。

預設值為 00:00:10 (10 秒) 。
maxRequestEntityAllowed 選擇性 uint 屬性。

指定可在要求實體主體中的位元組數目上限。 如果 Content-Length 標頭指定較大的數位,IIS 會傳送 HTTP 403 錯誤回應。

預設值為 4294967295 無限制) (。
uploadReadAheadSize 選擇性 uint 屬性。

指定網頁伺服器將讀取到緩衝區並傳遞至 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 來設定這些設定時,請務必將 認可 參數 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()