概要
<bindings>
要素の <binding>
要素を使用すると、要求が Web サイトと通信するために必要な情報を構成できます。
Web サイトを作成するときにバインド情報を構成することも、サイトの作成後にバインド情報を編集することもできます。 バインド情報には、クライアントがサイトとの通信に使用するプロトコル、サイトの IP アドレス、ポート番号、およびホスト ヘッダーが含まれます。
<binding>
要素には、バインド情報を構成するための 2 つの属性 (bindingInformation と protocol) が含まれます。 bindingInformation 属性には、サイトの IP アドレス、ポート番号、および必要に応じてホスト ヘッダーが含まれます。 protocol 属性は、サイトとの通信に使用するプロトコルを定義します。
互換性
バージョン | メモ |
---|---|
IIS 10.0 | <binding> 要素は IIS 10.0 では変更されませんでした。 |
IIS 8.5 | <binding> 要素は IIS 8.5 では変更されませんでした。 |
IIS 8.0 | Secure Sockets Layer 証明書に使用されるバインドを指定するために、sslFlags 属性が追加されました。 |
IIS 7.5 | <binding> 要素は IIS 7.5 では変更されませんでした。 |
IIS 7.0 | <bindings> コレクションの <binding> 要素は IIS 7.0 で導入されました。 |
IIS 6.0 | <bindings> コレクションは、IIS 6.0 の IIsWebServer メタベース オブジェクトの ServerBindings プロパティのセクションを置き換えます。 |
段取り
<binding>
要素は IIS 7 以降の既定のインストールに含まれています。
操作方法
既定のバインド情報をサーバーに追加する方法
次のようにインターネット インフォメーション サービス (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) マネージャー] をダブルクリックします。
[接続] ウィンドウでサーバー名を選びます。
[ホーム] ペインで、[構成エディター] をダブルクリックします。
[セクション] の system.applicationHost/sites に移動します。
[サイト バインド] ダイアログ ボックスの [追加...]をクリックします。
siteDefaults を展開します。
bindings を選び、右側の省略記号をクリックしてコレクション エディターを開きます。
[追加] をクリックし、bindingInformation、protocol、sslFlags の値を入力します。
コレクション エディターを閉じ、[操作] ウィンドウで [適用] をクリックします。
構成
ApplicationHost.config ファイルの <siteDefaults>
セクションの <bindings>
要素内に、既定の <binding>
要素を追加できます。
属性 | 説明 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bindingInformation |
必須の文字列属性です。 サイトと通信するための情報を指定します。 たとえば、Web サイト バインドには、サイトとの通信に使用される IP アドレス (未指定の IP アドレス)、ポート番号、および省略可能なホスト ヘッダーが含まれます。 |
||||||||||||||||||
protocol |
必須の文字列属性です。 サイトと通信するためのプロトコルを指定します。 |
||||||||||||||||||
sslFlags |
フラグの種類と同様に動作する省略可能な uint 属性で、次のフラグを指定できます。
Server Name Indication (SNI) を使用すると、SSL ハンドシェイクの一環としてホスト名がやり取りされます。 SNI は、HTTPS の種類を持つバインドを追加するときに、 サイト バインドの追加 ダイアログ ボックスで有効になります。 これは、1 つのネットワーク アドレスで複数のサーバーをホストする SSL 接続に役立ちます。 4 より大きい値は、IIS 10 バージョン 1809 以降でのみサポートされます。 既定値は 0 です。 |
子要素
なし。
構成サンプル
次の構成サンプルでは、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()