次の方法で共有


Web サイトの制限 <limits>

概要

<site> 要素の <limits> 要素は、サイトへのクライアント要求の帯域幅の量、接続数、または接続タイムアウトを制限する設定を構成します。

Note

特定のサイトに対して <siteDefaults> セクションと <site> セクションの両方に <limits> 要素が構成されている場合は、<site> セクションの構成がそのサイトに対して使用されます。

互換性

バージョン メモ
IIS 10.0 <limits> 要素は IIS 10.0 では変更されませんでした。
IIS 8.5 <limits> 要素は IIS 8.5 では変更されませんでした。
IIS 8.0 URL に許可されるセグメントの最大数を指定するために、maxUrlSegments 属性が追加されました。
IIS 7.5 <limits> 要素は IIS 7.5 では変更されませんでした。
IIS 7.0 <site> 要素の <limits> 要素が IIS 7.0 で導入されました。
IIS 6.0 <limits> 要素は、次の IIS 6.0 メタベース設定を置き換えます。
  • ConnectionTimeout
  • MaxBandwidth
  • MaxConnections

段取り

<site> 要素の <limits> 要素は、IIS 7 以降の既定のインストールに含まれています。

操作方法

サイトに対して接続制限オプションを構成する方法

  1. 次のようにインターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] をクリックし、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
      • [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンをクリックし、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順にクリックします。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウでサーバー名を展開し、[サイト] ノードを展開してから、サイトの名前をクリックします。

  3. サイトの [ホーム] ウィンドウで、[操作] ウィンドウの [詳細設定...] をクリックします。

  4. [詳細設定] ダイアログ ボックスで、[接続]を展開し、接続の制限オプションを指定して、[OK] をクリックします。

    Screenshot of the Advanced dialog box. Limits is highlighted and expanded.

構成

属性

属性 説明
connectionTimeout 省略可能な timeSpan 属性。

非アクティブであるとみなされた接続を切断する前に IIS が待機する時間 (秒) を指定します。 接続は、次の理由で非アクティブであるとみなされる可能性があります。
  • HTTP.sys Timer_ConnectionIdle タイマーの有効期限が切れた。 接続は有効期限が切れ、アイドル状態のままになります。
  • HTTP.sys Timer_EntityBody タイマーの有効期限が切れた。 接続は、要求エンティティ本文が到着する前に、有効期限が切れました。 要求にエンティティ本文があることが明らかなときは、HTTP API が Timer_EntityBody タイマーをオンにします。 当初は、このタイマーの制限は connectionTimeout 値に設定されます。 この要求で別のデータ提示が受信されるたびに、HTTP API がタイマーをリセットして、connectionTimeout 属性で指定されているより長い分数を接続に許可します。
  • HTTP.sys Timer_AppPool タイマーの有効期限が切れた。 接続は、サーバー アプリケーションがデキューして処理するのを、要求がアプリケーション プール キュー内で待機する時間が長すぎたために、有効期限が切れました。 このタイムアウト期間は connectionTimeout です。
既定値は 00:02:00 (2 分) です。
maxBandwidth 省略可能な uint 属性。

サイトに使用される最大ネットワーク帯域幅 (バイト/秒) を指定します。 この設定は、IIS アクティビティによってネットワークが過負荷になるのを防止するために使用します。

既定値は 4294967295 です。
maxConnections 省略可能な uint 属性。

サイトの最大接続数を指定します。 この設定は、同時クライアント接続の数を制限するために使用します。

既定値は 4294967295 です。
maxurlSegments 省略可能な uint 属性。

URL に許可されるセグメントの最大数を指定します。

既定値は 32 です。

子要素

なし。

構成サンプル

次の構成サンプルは、最大帯域幅が 65,536 バイト/秒に設定され、接続の最大数が 1,024 に設定され、接続タイムアウトが 1 分に設定されている Web サイトを示しています。

<sites>
   <site name="Default Web Site" id="1" serverAutoStart="true">
      <application path="/">
         <virtualDirectory path="/"
            physicalPath="%SystemDrive%\inetpub\wwwroot" />
      </application>
      <bindings>
         <binding protocol="http"
            bindingInformation="*:80:" />
      </bindings>
     <limits maxBandwidth="65536"
         maxConnections="1024"
         connectionTimeout="00:01:00" />
   </site>
</sites>

サンプル コード

次のコード サンプルは、65,536 バイト/秒の最大帯域幅、1,024 の最大接続数、1 分の接続タイムアウトの Default Web Site を構成します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].limits.maxBandwidth:65536" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].limits.maxConnections:1024" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].limits.connectionTimeout:00:01:00" /commit:apphost

Note

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 sitesSection = config.GetSection("system.applicationHost/sites");
         ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

         ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Default Web Site");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElement limitsElement = siteElement.GetChildElement("limits");
         limitsElement["maxBandwidth"] = 65536;
         limitsElement["maxConnections"] = 1024;
         limitsElement["connectionTimeout"] = TimeSpan.Parse("00:01:00");

         serverManager.CommitChanges();
      }
   }

   private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            bool matches = true;
            for (int i = 0; i < keyValues.Length; i += 2)
            {
               object o = element.GetAttributeValue(keyValues[i]);
               string value = null;
               if (o != null)
               {
                  value = o.ToString();
               }
               if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
               {
                  matches = false;
                  break;
               }
            }
            if (matches)
            {
               return element;
            }
         }
      }
      return null;
   }
}

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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
      Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection

      Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "Default Web Site")
      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim limitsElement As ConfigurationElement = siteElement.GetChildElement("limits")
      limitsElement("maxBandwidth") = 65536
      limitsElement("maxConnections") = 1024
      limitsElement("connectionTimeout") = TimeSpan.Parse("00:01:00")

       serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
      For Each element As ConfigurationElement In collection
         If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
            Dim matches As Boolean = True
            Dim i As Integer
            For i = 0 To keyValues.Length - 1 Step 2
               Dim o As Object = element.GetAttributeValue(keyValues(i))
               Dim value As String = Nothing
               If (Not (o) Is Nothing) Then
                  value = o.ToString
               End If
               If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                  matches = False
                  Exit For
               End If
            Next
            If matches Then
               Return element
            End If
         End If
      Next
      Return Nothing
   End Function


End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");

var sitesCollection = sitesSection.Collection;
var siteElementPos = FindElement(sitesCollection, "site", ["name", "Default Web Site"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);

var limitsElement = siteElement.ChildElements.Item("limits");
limitsElement.Properties.Item("maxBandwidth").Value = 65536;
limitsElement.Properties.Item("maxConnections").Value = 1024;
limitsElement.Properties.Item("connectionTimeout").Value = "00:01:00";

adminManager.CommitChanges();

function FindElement(collection, elementTagName, valuesToMatch) {
   for (var i = 0; i < collection.Count; i++) {
      var element = collection.Item(i);
      if (element.Name == elementTagName) {
         var matches = true;
         for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
            var property = element.GetPropertyByName(valuesToMatch[iVal]);
            var value = property.Value;
            if (value != null) {
               value = value.toString();
            }
            if (value != valuesToMatch[iVal + 1]) {
               matches = false;
               break;
            }
         }
         if (matches) {
            return i;
         }
      }
   }
   return -1;
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")

Set sitesCollection = sitesSection.Collection
siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))
If siteElementPos = -1 Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)

Set limitsElement = siteElement.ChildElements.Item("limits")
limitsElement.Properties.Item("maxBandwidth").Value = 65536
limitsElement.Properties.Item("maxConnections").Value = 1024
limitsElement.Properties.Item("connectionTimeout").Value = "00:01:00"

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not IsNull(value) Then
               value = CStr(value)
            End If
            If Not value = CStr(valuesToMatch(iVal + 1)) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function