Configuration History <configHistory>

Overview

The <configHistory> element defines the settings for the built-in IIS configuration history feature, which keeps a running history of changes to your configuration files. This history is especially useful for recovering from mistakes made when manually editing your configuration files.

For example, if you were making changes to your ApplicationHost.config file and the changes contained invalid syntax, end users would see the following error when browsing to your Web site:

HTTP Error 503. The service is unavailable.

To resolve the issue, you would only need to copy the ApplicationHost.config from the history folder into your %windir%\system32\inetsrv\config folder in order to restore your server to operational state.

Note

The configuration history feature requires that the Application Host Help Service is running on your server; if this service is stopped or disabled, changes to your configuration files will not be kept in the history folder.

Compatibility

Version Notes
IIS 10.0 The <configHistory> element was not modified in IIS 10.0.
IIS 8.5 The <configHistory> element was not modified in IIS 8.5.
IIS 8.0 The <configHistory> element was not modified in IIS 8.0.
IIS 7.5 The <configHistory> element was not modified in IIS 7.5.
IIS 7.0 The <configHistory> element was introduced in IIS 7.0.
IIS 6.0 The <configHistory> element replaces the EnableHistory and MaxHistoryFiles attributes of the IIS 6.0 IIsComputerSetting metabase object.

Setup

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

How To

There is no user interface for setting the configuration history options for IIS 7. For examples of how to set the configuration history options programmatically, see the Code Samples section of this document.

Configuration

Attributes

Attribute Description
enabled Optional Boolean attribute.

Specifies whether configuration history is enabled.

The default value is true.
path Optional string attribute.

Specifies the path to the configuration history files.

The default value is %SystemDrive%\inetpub\history.
maxHistories Optional uint attribute.

Specifies the maximum number of history files to keep.

The default value is 10.
period Optional timeSpan attribute.

Specifies the interval that IIS uses to check for configuration changes.

The default value is 00:02:00 (two minutes).

Child Elements

None.

Configuration Sample

The following configuration sample enables the configuration history feature, sets the path of the history files to %SystemDrive%\inetpub\history, sets the maximum number of history files to 50, and sets the history interval to 5 minutes.

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

Sample Code

The following code samples enable configuration history for IIS 7, and configure the following options: the path of the history files is set to %SystemDrive%\inetpub\history, the maximum number of history files is set to 50, and the time interval for checking the configuration settings is set to 5 minutes.

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

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