次の方法で共有


Web サイトの既定の HSTS 設定 <hsts>

概要

<siteDefaults> 要素の <hsts> 要素には、IIS 10.0 バージョン 1709 以降のサイトの既定の HTTP Strict Transport Security (HSTS) 設定を構成できる属性が含まれています。

Note

特定のサイトに対して <siteDefaults> セクションと <site> セクションの両方に <hsts> 要素が構成されている場合は、<site> セクションの構成がそのサイトに対して使用されます。

互換性

バージョン メモ
IIS 10.0 バージョン 1709 <siteDefaults> 要素の <hsts> 要素は IIS 10.0 バージョン 1709 で導入されました。
IIS 10.0 該当なし
IIS 8.5 該当なし
IIS 8.0 該当なし
IIS 7.5 該当なし
IIS 7.0 該当なし
IIS 6.0 該当なし

段取り

<siteDefaults> 要素の <hsts> 要素は、IIS 10.0 バージョン 1709 以降の既定のインストールに含まれています。

操作方法

IIS 10.0 バージョン 1709 の <siteDefaults> 要素の <hsts> 要素を構成できるユーザー インターフェイスはありません。 <siteDefaults> 要素の <hsts> 要素をプログラムで構成する方法の例については、このドキュメントの「サンプル コード」セクションを参照してください。

構成

属性

属性 説明
enabled 省略可能な Boolean 属性です。

サイトの HSTS が有効 (true) か無効 (false) かを指定します。 HSTS が有効になっている場合、IIS が Web サイトに HTTPS 要求を応答するときに Strict-Transport-Security HTTP 応答ヘッダーが追加されます。

既定値は false です。
max-age 省略可能な uint 属性。

Strict-Transport-Security HTTP 応答ヘッダー フィールド値の max-age ディレクティブを指定します。

既定値は 0 です。
includeSubDomains 省略可能な Boolean 属性です。

includeSubDomains ディレクティブを Strict-Transport-Security HTTP 応答ヘッダー フィールド値に含めるかどうかを指定します。

注: すべてのサブドメインが実際に TLS/SSL 経由で HTTP ベースのサービスを提供している場合にのみ、この属性を有効にします。

既定値は false です。
preload 省略可能な Boolean 属性です。

preload ディレクティブを Strict-Transport-Security HTTP 応答ヘッダー フィールド値に含めるかどうかを指定します。

注: HSTS プリロード リストに含めるためにサイトのドメインが送信されている場合にのみ、この属性を有効にします。

既定値は false です。
redirectHttpToHttps 省略可能な Boolean 属性です。

HTTP から HTTPS へのリダイレクトが有効 (true) か無効 (false) かを指定します。

注: redirectHttpToHttps を有効にすると、サイト レベルでの HTTP から HTTPS へのリダイレクトが強制されます。 IIS では HTTP 要求をリダイレクトするとき、URI スキームを "https" に置き換え、ポート コンポーネントを無視します。 リダイレクト先が、標準ポート 443 で TLS/SSL 経由の HTTP ベースのサービスを提供していることを確認します。

既定値は false です。

子要素

なし。

構成サンプル

次の構成サンプルでは、IIS 10.0 バージョン 1709 以降に対して既定の <hsts> オプションを指定します。

<system.applicationHost>
    <sites>
        <siteDefaults>
            <hsts enabled="true" max-age="31536000" includeSubDomains="true" redirectHttpToHttps="true" />
        </siteDefaults>
    </sites>
</system.applicationHost>

サンプル コード

次のコード サンプルでは、IIS 10.0 バージョン 1709 以降に対して既定の <hsts> オプションを構成します。

AppCmd.exe

appcmd.exe set config  -section:system.applicationHost/sites /siteDefaults.hsts.enabled:"True" /commit:apphost
appcmd.exe set config  -section:system.applicationHost/sites /siteDefaults.hsts.max-age:"31536000" /commit:apphost
appcmd.exe set config  -section:system.applicationHost/sites /siteDefaults.hsts.includeSubDomains:"True" /commit:apphost
appcmd.exe set config  -section:system.applicationHost/sites /siteDefaults.hsts.redirectHttpToHttps:"True" /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");
            
            ConfigurationElement hstsElement = siteDefaultsElement.GetChildElement("hsts");
            hstsElement["enabled"] = true;
            hstsElement["max-age"] = 31536000;
            hstsElement["includeSubDomains"] = true;
            hstsElement["redirectHttpToHttps"] = true;
            
            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 hstsElement As ConfigurationElement = siteDefaultsElement.GetChildElement("hsts")
      hstsElement("enabled") = True
      hstsElement("max-age") = 31536000
      hstsElement("includeSubDomains") = True
      hstsElement("redirectHttpToHttps") = True

      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 hstsElement = siteDefaultsElement.ChildElements.Item("hsts");
hstsElement.Properties.Item("enabled").Value = true;
hstsElement.Properties.Item("max-age").Value = 31536000;
hstsElement.Properties.Item("includeSubDomains").Value = true;
hstsElement.Properties.Item("redirectHttpToHttps").Value = true;

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 hstsElement  = siteDefaultsElement.ChildElements.Item("hsts")
hstsElement.Properties.Item("enabled").Value = True
hstsElement.Properties.Item("max-age").Value = 31536000
hstsElement.Properties.Item("includeSubDomains").Value = True
hstsElement.Properties.Item("redirectHttpToHttps").Value = True

adminManager.CommitChanges()

IISAdministration PowerShell コマンドレット

Import-Module IISAdministration
Reset-IISServerManager -Confirm:$false
Start-IISCommitDelay

$sitesCollection = Get-IISConfigSection -SectionPath "system.applicationHost/sites" | Get-IISConfigCollection
$siteDefaultsElement = Get-IISConfigElement -ConfigElement $sitesCollection -ChildElementName "siteDefaults"
$hstsElement = Get-IISConfigElement -ConfigElement $siteDefaultsElement -ChildElementName "hsts"
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "enabled" -AttributeValue $true
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "max-age" -AttributeValue 31536000
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "includeSubDomains" -AttributeValue $true
Set-IISConfigAttributeValue -ConfigElement $hstsElement -AttributeName "redirectHttpToHttps" -AttributeValue $true

Stop-IISCommitDelay
Remove-Module IISAdministration