共用方式為


新增預設系結系結<>

概觀

元素 <binding><bindings> 元素可讓您設定要求與網站通訊所需的資訊。

您可以在建立網站時設定系結資訊,也可以在建立網站之後編輯系結資訊。 系結資訊包括用戶端用來與月台通訊的通訊協定、月臺的IP位址、埠號碼和主機標頭。

元素 <binding> 包含兩個屬性來設定系結資訊: bindingInformation通訊協定bindingInformation 屬性包含IP位址、埠號碼,以及月臺的主機標頭。 通訊 協定 屬性會定義用來與月台通訊的通訊協定。

相容性

版本 備註
IIS 10.0 <binding> 在 IIS 10.0 中修改專案。
IIS 8.5 專案 <binding> 未在 IIS 8.5 中修改。
IIS 8.0 sslFlags 新增 屬性以指定用於安全套接字層憑證的系結。
IIS 7.5 專案 <binding> 未在 IIS 7.5 中修改。
IIS 7.0 集合 <binding><bindings> 元素是在 IIS 7.0 中引進的。
IIS 6.0 集合<bindings>會取代 IIS 6.0 IIsWebServer Metabase 物件上 ServerBindings 屬性的區段。

設定

專案 <binding> 包含在 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. 移至 區段中system.applicationHost/sites

  5. 在 [ 網站系結] 對話框中,按兩下 [ 新增...]。

  6. 展開 siteDefaults

  7. 選取 結,然後按下右側的省略號,以開啟集合編輯器。

    [網站系結] 對話框的螢幕快照,其中顯示 [網站預設值] 節點已展開,並已選取 [系結]。

  8. 按兩下 [新增],然後輸入 bindingInformationprotocolsslFlags 的值

  9. 關閉 集合編輯器 ,然後在 [ 動作] 窗格中,按兩下 [ 套用]。

組態

您可以在 ApplicationHost.config 檔案的 區段中,於 元素<siteDefaults><bindings>新增預設<binding>元素。

屬性 描述
bindingInformation 必要的字串屬性。

指定要與網站通訊的資訊。 例如,網站系結包含IP位址(或未指定的IP位址)、埠號碼,以及用來與網站通訊的選擇性主機標頭。
protocol 必要的字串屬性。

指定與月台通訊的通訊協定。
sslFlags 使用類似旗標類型的選擇性 uint 屬性,具有下列可能的旗標:
Description
0 使用IP/埠組合建立的安全連線。 只有一個憑證可以系結至IP位址和埠的組合。
1 使用埠號碼和使用伺服器名稱指示 (SNI) 取得之主機名的安全連線。
2 使用集中式 SSL 證書存儲建立安全連線。
4 停用 HTTP/2。
8 停用 OCSP 裝訂。
16 停用 QUIC。
32 停用 TCP 的 TLS 1.3。
64 停用舊版 TLS。
集中式 SSL 憑證支援可讓您建立可包含多個憑證檔案的集中式證書存儲。 憑證檔案可以命名,以對應至其所包含的主機名。 這可建立只需要埠的系結,而不是IP/埠或主機名/埠組合。 當要求傳入時,IIS 會比對埠、從要求判斷主機名,並搜尋具有相符名稱的憑證檔案的集中式證書存儲。 它會使用該憑證。

使用伺服器名稱指標 (SNI),主機名會交換為 SSL 交握的一部分。 新增具有 HTTPS 類型的系結時,會在 [新增網站系結] 對話框中啟用 SNI。 這適用於在單一網路位址上裝載多部伺服器的 SSL 連線。

只有 IIS 10 1809 版和更新版本才支援大於 4 的值。 預設值是 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

注意

當您使用 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 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()