Skip to content

Latest commit

 

History

History
115 lines (78 loc) · 4.75 KB

File metadata and controls

115 lines (78 loc) · 4.75 KB
title author description ms.date ms.assetid msc.legacyurl msc.type
Custom Headers <customHeaders>
rick-anderson
Overview The <customHeaders> element of the <httpProtocol> element specifies custom HTTP headers that Internet Information Services (IIS) 7 will...
09/26/2016
c6cedc17-5db1-4a74-935f-ba286d203d3e
/configreference/system.webserver/httpprotocol/customheaders
config

Custom Headers <customHeaders>

Overview

The <customHeaders> element of the <httpProtocol> element specifies custom HTTP headers that Internet Information Services (IIS) 7 will return in HTTP responses from the Web server.

Note

HTTP headers are name and value pairs that are returned in responses from a Web server. Custom response headers are sent to the client together with the default HTTP header. Unlike redirect response headers, which are returned in responses only when redirection occurs, custom response headers are returned in every response.

Compatibility

Version Notes
IIS 10.0 The <customHeaders> element was not modified in IIS 10.0.
IIS 8.5 The <customHeaders> element was not modified in IIS 8.5.
IIS 8.0 The <customHeaders> element was not modified in IIS 8.0.
IIS 7.5 The <customHeaders> element was not modified in IIS 7.5.
IIS 7.0 The <customHeaders> element of the <httpProtocol> element was introduced in IIS 7.0.
IIS 6.0 The <customHeaders> element replaces the IIS 6.0 HttpCustomHeaders metabase object.

Setup

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

How To

How to set custom HTTP headers for a Web site or application

  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, go to the site, application, or directory for which you want to set a custom HTTP header.

  3. In the Home pane, double-click HTTP Response Headers.
    Screenshot that shows the Home pane with H T T P Response Headers selected.

  4. In the HTTP Response Headers pane, click Add... in the Actions pane.
    Screenshot of H T T P Response Headers pane with Add option displayed in the Actions pane.

  5. In the Add Custom HTTP Response Header dialog box, set the name and value for your custom header, and then click OK.
    Screenshot of Add Custom H T T P Header dialog box with fields for name and value for custom header.

Configuration

Attributes

None.

Child Elements

Element Description
add Optional element.

Adds a custom response header to the <customHeaders> collection.
clear Optional element.

Removes all references to custom response headers from the <customHeaders> collection.
remove Optional element.

Removes a reference to a custom response header from the <customHeaders> collection.

Configuration Sample

The following configuration sample sets a custom HTTP header and value.

[!code-xmlMain]

Note

The following default <httpProtocol> element is configured in the ApplicationHost.config file in IIS 7.

[!code-xmlMain]

Sample Code

The following code samples set a custom HTTP header and value.

AppCmd.exe

[!code-consoleMain]

C#

[!code-csharpMain]

VB.NET

[!code-vbMain]

JavaScript

[!code-javascriptMain]

VBScript

[!code-vbMain]