Bindings

09/26/2016

6 分钟可看完

本文内容

Overview

The element configures binding information for an IIS 7 or later Web site. It can also define the default bindings for all sites on the Web server if it is included in the element.

This element can contain a collection of 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 element in the element to override binding defaults inherited from the server level element.

Compatibility

Version

Notes

IIS 10.0

The element was not modified in IIS 10.0.

IIS 8.5

The element was not modified in IIS 8.5.

IIS 8.0

The element was not modified in IIS 8.0.

IIS 7.5

The element was not modified in IIS 7.5.

IIS 7.0

The element was introduced in IIS 7.0.

IIS 6.0

The collection replaces sections of the ServerBindings property on the IIS 6.0 IIsWebServer metabase object.

Setup

The element is included in the default installation of IIS 7 or later.

How To

How to add binding information to a site

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.

In the Connections pane, expand the server name, expand Sites, and then click the Web site on which you want to configure the bindings.

In the Actions pane, click Bindings...

In the Site Bindings dialog box, click Add...

In the Add Site Binding dialog box, add the binding information, and then click OK.

Configuration

You can add a element for each site in the ApplicationHost.config file, which can contain a collection of individual elements that define the individual protocol bindings for the site. Each site will need at least one HTTP or HTTPS binding to be viewable over the Internet.

You can also use element in the element to override binding defaults inherited from the server level element.

Attributes

None.

Child Elements

Element

Description

Optional element.

Configures a binding in the parent site.

clear

Optional element.

Clears references to default settings that are inherited from the parent level of the configuration.

Configuration Sample

The following example defines a site named Contoso with two bindings. The first binding is for a hostname of "www.contoso.com" on port 80 for the IP address of 192.168.0.1, and the second binding is for an HTTPS binding for all IP addresses over port 443.

Sample Code

The following examples configure a site named Contoso with a hostname of "www.contoso.com" on port 80 for the IP address of 192.168.0.1, and an HTTPS binding for all IP addresses over port 443.

AppCmd.exe

appcmd.exe set site /site.name:Contoso /+bindings.[protocol='http',bindingInformation='192.168.0.1:80:www.contoso.com']

appcmd.exe set site /site.name:Contoso /+bindings.[protocol='https',bindingInformation='*:443:']

Or you can use:

appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso'].bindings.[protocol='http',bindingInformation='192.168.0.1:80:www.contoso.com']" /commit:apphost

appcmd.exe set config -section:system.applicationHost/sites /+"[name='Contoso'].bindings.[protocol='https',bindingInformation='*:443:']" /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");

ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Contoso");

if (siteElement == null) throw new InvalidOperationException("Element not found!");

ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");

ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");

bindingElement["protocol"] = @"http";

bindingElement["bindingInformation"] = @"192.168.0.1:80:www.contoso.com";

bindingsCollection.Add(bindingElement);

ConfigurationElement bindingElement1 = bindingsCollection.CreateElement("binding");

bindingElement1["protocol"] = @"https";

bindingElement1["bindingInformation"] = @"*:443:";

bindingsCollection.Add(bindingElement1);

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", "Contoso")

If (siteElement Is Nothing) Then

Throw New InvalidOperationException("Element not found!")

End If

Dim bindingsCollection As ConfigurationElementCollection = siteElement.GetCollection("bindings")

Dim bindingElement As ConfigurationElement = bindingsCollection.CreateElement("binding")

bindingElement("protocol") = "http"

bindingElement("bindingInformation") = "192.168.0.1:80:www.contoso.com"

bindingsCollection.Add(bindingElement)

Dim bindingElement1 As ConfigurationElement = bindingsCollection.CreateElement("binding")

bindingElement1("protocol") = "https"

bindingElement1("bindingInformation") = "*:443:"

bindingsCollection.Add(bindingElement1)

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", "Contoso"]);

if (siteElementPos == -1) throw "Element not found!";

var siteElement = sitesCollection.Item(siteElementPos);

var bindingsCollection = siteElement.ChildElements.Item("bindings").Collection;

var bindingElement = bindingsCollection.CreateNewElement("binding");

bindingElement.Properties.Item("protocol").Value = "http";

bindingElement.Properties.Item("bindingInformation").Value = "192.168.0.1:80:www.contoso.com";

bindingsCollection.AddElement(bindingElement);

var bindingElement1 = bindingsCollection.CreateNewElement("binding");

bindingElement1.Properties.Item("protocol").Value = "https";

bindingElement1.Properties.Item("bindingInformation").Value = "*:443:";

bindingsCollection.AddElement(bindingElement1);

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 = 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", "Contoso"))

If siteElementPos = -1 Then

WScript.Echo "Element not found!"

WScript.Quit

End If

Set siteElement = sitesCollection.Item(siteElementPos)

Set bindingsCollection = siteElement.ChildElements.Item("bindings").Collection

Set bindingElement = bindingsCollection.CreateNewElement("binding")

bindingElement.Properties.Item("protocol").Value = "http"

bindingElement.Properties.Item("bindingInformation").Value = "192.168.0.1:80:www.contoso.com"

bindingsCollection.AddElement(bindingElement)

Set bindingElement1 = bindingsCollection.CreateNewElement("binding")

bindingElement1.Properties.Item("protocol").Value = "https"

bindingElement1.Properties.Item("bindingInformation").Value = "*:443:"

bindingsCollection.AddElement(bindingElement1)

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

iis服务器修改端口,Bindings bindings相关推荐

  1. iis服务器修改端口,Apache、Nginx、IIS服务器修改网站端口教程

    以下分别介绍Apache.Nginx.IIS服务器修改网站端口的基本方法. 一.针对Apache服务器 找到 httpd.conf 文件,一般在 Apache 安装目录的 conf 文件夹下就能看到该 ...

  2. 访问服务器80端口显示iis,iis服务器80端口一直与本机建立连接解决思路

    iis服务器80端口一直与本机建立连接解决思路 iis服务器80端口一直与本机建立连接解决思路 日期:2014-05-16 浏览次数:20995 次 iis服务器80端口一直与本机建立连接 iis服务 ...

  3. iis服务器修改内存,修改IIS的虚拟内存

    关于要修改IIS的虚拟内存,此问题无异于要配置IIS应用程序池了,否则的话,服务器经常产生"应用程序池 'DefaultAppPool' 提供服务的进程关闭时间超过了限制.进程 ID 是 ' ...

  4. 服务器显示AL018是什么意思,IIS服务器80端口却已被占用的问题

    一.问题背景 在IIS中发布一个asp网站,发现无法使用80端口,错误为"无法启动该网站.其它网站可能正在使用同一端口".但其实IIS的其它网站已经没有使用该端口了.这就需要设计到 ...

  5. 华为云 服务器修改端口,【华为云服务之】修改华为云ECS服务器安全组

    在创建ECS服务器后(可参照本人博文),如果我们创建了新的应用而要提供给外部访问(比如增加了新的WEB应用,新的端口等)时,由于在创建ECS的时候我们不可能规划全部的开放端口,为也安全我们也不可能开放 ...

  6. 魔兽服务器修改端口,魔兽怀旧服:PTR四项全新改动,开放仇恨端口,或将影响副本难度...

    原标题:魔兽怀旧服:PTR四项全新改动,开放仇恨端口,或将影响副本难度 魔兽世界怀旧服第四阶段已经开放了一段时间,而第四阶段本身就没有太多的内容,因此玩家们也越来越期待第五阶段早些到来,不过暴雪却一直 ...

  7. Web服务器启动端口冲突问题

    如果Web服务要使用的端口已经被其它的应用程序占用,就会导致端口冲突,一般会报出下面的异常: java.net.BindException: Address already in use: JVM_B ...

  8. Apache Http Server 解决不同域名共用服务器80端口问题

    今天部署网站时,用户突然说他们只有一台服务器,一个公网IP,而且现在服务器上已经有一个发布中的网站(显然80端口已被占用),让我们想想办法怎么样才能部署我们的项目到他们服务器上,而且使用同一台服务器, ...

  9. iis ftp服务器修改端口号,iis ftp服务器指定端口

    iis ftp服务器指定端口 内容精选 换一换 以IDE Daemon服务器的时间为准,将Host侧服务器的时间与IDE Daemon服务器的时间同步.以HwHiAiUser用户登录Host侧服务器. ...

最新文章

  1. 云计算如何帮助直播行业发展
  2. wifi 2.4g 5g 区别_wifi信号差,网速慢?可能是你没有配置好2.4G和5G WiFi
  3. iOS PUSH实现的简单步骤
  4. Java实现最电话号码的简单加密源码
  5. IEEE1459功率理论计算方法
  6. 苏州大学计算机组成与结构,苏州大学计算机组成结构期末.docx
  7. [Swift]LeetCode1017. 负二进制转换 | Convert to Base -2
  8. hive 将null值替换为0_【Hive】数据倾斜
  9. Spark内核解析之三:Spark 通讯架构
  10. img标签显示不出图片_前端开发,原生 JS 实现最简单的图片懒加载
  11. docker容器安装和配置实战
  12. 钉钉企业内部H5微应用开发
  13. 你知道电脑如何录制屏幕视频吗?快来看看这两个实用方法
  14. [OT]ubuntu下安装HP-P1108打印机驱动
  15. pl2303 USB转串口驱动
  16. java 修改文件编码_java中怎么获取、设置文件编码格式?
  17. dataframe筛选列名_python 查看列名_Pandas 库之 DataFrame - Python学习笔记
  18. 伦敦大学国王学院金融数学理学硕士研究生offer一枚
  19. CodeBlocks中文汉化Code::Blocks 10.05 中文版
  20. iOS开发中一些有用的小代码

热门文章

  1. 【魏先生搞定Python系列】一文搞定Cufflinks画图
  2. angular路由模拟微信页面切换和页面之间的传值
  3. win10不能上传文件到服务器,Win10系统下蓝牙无法传输文件怎么解决
  4. JPA Spring Data JPA详解
  5. C++实现matlab中的interp1和interp2插值
  6. void* 指针有什么用
  7. Node节点禁止调度(平滑维护)方式- cordon,drain,delete
  8. nginx配置详解(容器、负载)—官方原版
  9. oracle 视图、索引、序列、同义词
  10. Hive操作——删除表(drop、truncate)