構成履歴 <configHistory>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

概要

<configHistory> 要素は、構成ファイルへの変更の実行履歴を保持する、組み込みの IIS 構成履歴機能の設定を定義します。構成履歴は、構成ファイルを手動で編集する際に犯したミスから復旧する場合に、特に便利です。

たとえば、ApplicationHost.config ファイルの変更に無効な構文が含まれていた場合は、エンド ユーザーが Web サイトをブラウズすると次のエラーが表示されます。

HTTP エラー 503。サービスを利用できません。

この問題が発生したときは、ApplicationHost.config を履歴フォルダーから %windir%\system32\inetsrv\config folder にコピーするだけで、サーバーを動作状態に復元できます。

: 構成履歴機能を使用するには、Application Host Helper Service がサーバーで実行されている必要があります。このサービスが停止状態または無効になっている場合、構成ファイルへの変更は履歴フォルダーに保存されません。

互換性

  IIS 7.0 IIS 6.0
注意 <configHistory> は IIS 7.0 で新たに導入された要素です。

<configHistory> 要素は、IIS 6.0 の IIsComputerSetting メタベース オブジェクトの EnableHistory および MaxHistoryFiles 属性に代わるものです。

セットアップ

<configHistory> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

IIS 7.0 で構成履歴オプションを設定するためのユーザー インターフェイスはありません。構成履歴オプションをプログラムによって設定する方法の例については、このドキュメントの「サンプル コード」セクションを参照してください。

構成

属性

属性 説明
enabled オプションの Boolean 属性。

構成履歴を有効にするかどうかを指定します。

既定値は true です。
path オプションの string 属性。

構成履歴ファイルへのパスを指定します。

既定値は %SystemDrive%\inetpub\history です。
maxHistories オプションの unit 属性。

保持する履歴ファイルの最大数を指定します。

既定値は 10 です。
period オプションの timeSpan 属性。

IIS が構成変更をチェックする間隔を指定します。

既定値は 00:02:00 (2 分) です。

子要素

なし。

構成サンプル

次の構成サンプルでは、構成履歴機能を有効にして、履歴ファイルのパスを %SystemDrive%\inetpub\history に設定し、履歴ファイルの最大数を 50 に設定し、履歴間隔を 5 分に設定しています。

<system.applicationHost>

   <configHistory enabled="true"
      path="%SystemDrive%\inetpub\history"
      maxHistories="50"
      period="00:05:00" />
</system.applicationHost>

サンプル コード

次のコード サンプルでは、IIS 7.0 の構成履歴を有効にして、履歴ファイルのパスを %SystemDrive%\inetpub\history に設定し、履歴ファイルの最大数を 50 に設定し、構成設定をチェックする間隔を 5 分に設定しています。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/configHistory /enabled:"True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/configHistory /path:"%SystemDrive%\inetpub\history" /commit:apphost
appcmd.exe set config -section:system.applicationHost/configHistory /maxHistories:"50" /commit:apphost
appcmd.exe set config -section:system.applicationHost/configHistory /period:"00:05:00" /commit:apphost

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 configHistorySection = config.GetSection("system.applicationHost/configHistory");
         configHistorySection["enabled"] = true;
         configHistorySection["path"] = @"%SystemDrive%\inetpub\history";
         configHistorySection["maxHistories"] = 50;
         configHistorySection["period"] = TimeSpan.Parse("00:05:00");

         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 configHistorySection As ConfigurationSection = config.GetSection("system.applicationHost/configHistory")
      configHistorySection("enabled") = True
      configHistorySection("path") = "%SystemDrive%\inetpub\history"
      configHistorySection("maxHistories") = 50
      configHistorySection("period") = TimeSpan.Parse("00:05:00")

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var configHistorySection = adminManager.GetAdminSection("system.applicationHost/configHistory", "MACHINE/WEBROOT/APPHOST");
configHistorySection.Properties.Item("enabled").Value = true;
configHistorySection.Properties.Item("path").Value = "%SystemDrive%\\inetpub\\history";
configHistorySection.Properties.Item("maxHistories").Value = 50;
configHistorySection.Properties.Item("period").Value = "00:05:00";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set configHistorySection = adminManager.GetAdminSection("system.applicationHost/configHistory", "MACHINE/WEBROOT/APPHOST")
configHistorySection.Properties.Item("enabled").Value = True
configHistorySection.Properties.Item("path").Value = "%SystemDrive%\inetpub\history"
configHistorySection.Properties.Item("maxHistories").Value = 50
configHistorySection.Properties.Item("period").Value = "00:05:00"

adminManager.CommitChanges()