既定のバインド <bindings>

概要

<bindings> 要素は、すべての IIS 7 Web サイトの既定のバインド情報を構成します。

この要素には、<binding> 要素のコレクションを含められます。 コレクション内の各要素では、要求で Web サイトへの接続に使用できるバインド情報の個別のセットが定義されます。 たとえば、サイトでユーザーが HTTP プロトコルと HTTPS プロトコルの両方を使用して接続する必要がある場合は、各プロトコルのバインドを定義する必要があります。

<site> 要素の <bindings> 要素の <clear /> 要素を使用して、サーバー レベルの <siteDefaults> 要素から継承されたバインドの既定値をオーバーライドすることもできます。

互換性

バージョン メモ
IIS 10.0 <bindings> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <bindings> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <bindings> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <bindings> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <bindings> 要素が IIS 7.0 で導入されました。
IIS 6.0 <bindings> コレクションは、IIS 6.0 の IIsWebServer メタベース オブジェクトの ServerBindings プロパティのセクションを置き換えます。

段取り

<bindings> 要素は 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. サーバーの [サイト] ペインで、[操作] ウィンドウの [Web サイトの既定値の設定...] をクリックします。。
    [既定の Web サイト] オプションを示す [サイト] ウィンドウのスクリーンショット。

  4. [Web サイトの既定値] ダイアログ ボックスで、すべての Web サイトの既定のオプションを指定し、[OK] をクリックします。

    [全般] セクションと [動作] セクションを示す [Web サイトの既定値] ダイアログ ボックスのスクリーンショット。

構成

サーバーの <bindings> 要素を追加できます。これには、サーバーの既定のプロトコル バインドを定義する個々の <binding> 要素のコレクションを含めることができます。 <site> 要素の <bindings> 要素の <clear /> 要素を使用して、サーバー レベルの <siteDefaults> 要素から継承されたバインドの既定値をオーバーライドすることもできます。

属性

なし。

子要素

要素 説明
binding 省略可能な要素です。

既定のバインドを構成します。
clear 省略可能な要素です。

既定のバインドのコレクションを消去します。

構成サンプル

次の構成サンプルでは、IIS 7 に対して既定の bindings オプションを指定します。

<system.applicationHost>
   <sites>
      <siteDefaults>
         <bindings>
            <binding protocol="http" bindingInformation="127.0.0.1:8080:" />
         </bindings>
      </siteDefaults>
   </sites>
</system.applicationHost>

サンプル コード

次のコード サンプルでは、IIS 7 に対して既定の bindings オプションを構成します。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.bindings.[protocol='http',bindingInformation='*:8080:contoso.com'].bindingInformation:"127.0.0.1:8080:" /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");
         ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");

         ConfigurationElementCollection bindingsCollection = siteDefaultsElement.GetCollection("bindings");
         ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
         bindingElement["protocol"] = @"http";
         bindingElement["bindingInformation"] = @"127.0.0.1:8080:";
         bindingsCollection.Add(bindingElement);

         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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
      Dim siteDefaultsElement As ConfigurationElement = sitesSection.GetChildElement("siteDefaults")

      Dim bindingsCollection As ConfigurationElementCollection = siteDefaultsElement.GetCollection("bindings")
      Dim bindingElement As ConfigurationElement = bindingsCollection.CreateElement("binding")
      bindingElement("protocol") = "http"
      bindingElement("bindingInformation") = "127.0.0.1:8080:"
      bindingsCollection.Add(bindingElement)

      serverManager.CommitChanges()
   End Sub

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 siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults");

var bindingsCollection = siteDefaultsElement.ChildElements.Item("bindings").Collection;
var bindingElement = bindingsCollection.CreateNewElement("binding");
bindingElement.Properties.Item("protocol").Value = "http";
bindingElement.Properties.Item("bindingInformation").Value = "127.0.0.1:8080:";
bindingsCollection.AddElement(bindingElement);

adminManager.CommitChanges();

VBScript

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

Set bindingsCollection = siteDefaultsElement.ChildElements.Item("bindings").Collection
Set bindingElement = bindingsCollection.CreateNewElement("binding")
bindingElement.Properties.Item("protocol").Value = "http"
bindingElement.Properties.Item("bindingInformation").Value = "127.0.0.1:8080:"
bindingsCollection.AddElement(bindingElement)

adminManager.CommitChanges()