Default Bindings <bindings>

Overview

The <bindings> element configures the default binding information for all IIS 7 Web sites.

This element can contain a collection of <binding> elements. Each element in the collection defines a separate set of binding information that a request can use to contact the Web site. For example, if your site requires users to contact it using both the HTTP protocol and the HTTPS protocol, you must define a binding for each protocol.

You can also use a <clear /> element in the <bindings> element of a <site> element to override the binding defaults inherited from the server level <siteDefaults> element.

Compatibility

Version Notes
IIS 10.0 The <bindings> element was not modified in IIS 10.0.
IIS 8.5 The <bindings> element was not modified in IIS 8.5.
IIS 8.0 The <bindings> element was not modified in IIS 8.0.
IIS 7.5 The <bindings> element was not modified in IIS 7.5.
IIS 7.0 The <bindings> element was introduced in IIS 7.0.
IIS 6.0 The <bindings> collection replaces sections of the ServerBindings property on the IIS 6.0 IIsWebServer metabase object.

Setup

The <bindings> element is included in the default installation of IIS 7.

How To

How to configure the site defaults for a server

  1. Open Internet Information Services (IIS) Manager:

    • If you are using Windows Server 2012 or Windows Server 2012 R2:

      • On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows 8 or Windows 8.1:

      • Hold down the Windows key, press the letter X, and then click Control Panel.
      • Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    • If you are using Windows Server 2008 or Windows Server 2008 R2:

      • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
    • If you are using Windows Vista or Windows 7:

      • On the taskbar, click Start, and then click Control Panel.
      • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
  2. In the Connections pane, expand the server name, then click the Sites node.

  3. In the server's Sites pane, click Set Web Site Defaults... in the Actions pane.
    Screenshot of the Sites pane showing the Default Web Site option.

  4. In the Web Site Defaults dialog box, specify your default options for all Web sites, and then click OK.

    Screenshot of the Website Defaults dialog box showing the General and Behavior sections.

Configuration

You can add a <bindings> element for a server, which can contain a collection of individual <binding> elements that define the default protocol bindings for the server. You can also use a <clear /> element in the <bindings> element of a <site> element to override the binding defaults inherited from the server level <siteDefaults> element.

Attributes

None.

Child Elements

Element Description
binding Optional element.

Configures a default binding.
clear Optional element.

Clears the collection of default bindings.

Configuration Sample

The following configuration sample specifies the default bindings options for IIS 7.

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

Sample Code

The following code samples configure the default bindings options for IIS 7.

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

You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

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()