通过


配置重定向 <configurationRedirection>

概述

通过 <configurationRedirection> 元素,可将配置文件从集中的位置共享到 Web 场中的多个 Internet Information Services (IIS) 7 服务器计算机。 这样就可以配置 Web 场中的一个 IIS 7 服务器,然后在 Web 场中的所有 IIS 7 服务器之间共享生成的配置设置。 此元素还可用于将配置设置存储在一个 WEB 场中所有 Web 服务器计算机均可访问的 UNC 服务器上。

IIS 7.5 中的更改

IIS 7.5 中添加了两个新特性,用于控制 IIS 是否使用更改通知或 UNC 轮询来确定配置文件是否已更改。 这些属性包括:

  • enableUncPolling

    • 如果设置为 true,IIS 将定期检查 UNC 共享以测试配置文件是否已更新。
    • 如果设置为 false,将继续按 IIS 7.0 中原有的方式使用更改通知。
  • pollingPeriod:指定 IIS 要使用的 UNC 检查之间的时间间隔。

兼容性

版本 说明
IIS 10.0 <configurationRedirection> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <configurationRedirection> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <configurationRedirection> 元素在 IIS 8.0 中未进行修改。
IIS 7.5 enableUncPollingpollingPeriod 属性在 IIS 7.5 中添加。
IIS 7.0 <configurationRedirection> 元素在 IIS 7.0 中引入。
IIS 6.0 IIS 6.0 不支持共享配置。

安装

<configurationRedirection> 元素包含在 IIS 7 的默认安装中。

操作方式

如何导出配置设置并启用共享配置

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
  2. 在“连接”窗格中,选择要为其设置配置重定向的服务器连接。

  3. 在“主页”窗格中,双击“共享”配置。
    Screenshot of I I S manager Home pane. Shared Configuration icon selected.

  4. 在“操作”窗格中单击“导出配置”
    Screenshot of I I S Manager Actions pane.

  5. 在“导出配置”对话框中,在“物理路径”框中键入要导出的配置文件的目录路径,键入并确认加密密码,然后单击“确定”。
    Screenshot of Export Configuration window.

  6. 出现“导出配置”对话框时,单击“确定”。
    Screenshot of Export Configutation dialog box.

如何启用共享配置

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows 8 或 Windows 8.1:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
    • 如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:

      • 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows Vista 或 Windows 7:

      • 在任务栏上,单击“开始”,然后单击“控制面板”。
      • 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
  2. 在“连接”窗格中,选择要为其设置配置重定向的服务器连接。

  3. 在“主页”窗格中,双击“共享”配置。
    Screenshot of Home pane with Shared Configuration icon highlighted.

  4. 在“共享的配置”窗格中,选中“启用共享的配置”选项。

  5. 在“物理路径”框中,键入共享的配置文件的路径,在“用户名”框中键入有权访问共享的配置文件的帐户名称,在“密码”框中键入帐户的密码,然后在“确认密码”框中再次键入帐户密码。
    Screenshot of Shared Configuration window.

  6. 在“操作”窗格中,单击“应用”

  7. 在“加密密钥密码”对话框的“输入加密密钥”框中,键入在步骤 5 中创建的加密密钥的密码,然后单击“确定”。
    Screenshot of encryption key password box.

  8. 在出现的每个“共享的配置”对话框中,单击“确定”以关闭对话框。
    Screenshot of shared configuration dialog about existing I I S eccryption keys.
    Screenshot of shared configuration dialog box about restarting I I S Manager.

    注意

    须先关闭并重启 IIS 管理器,这些配置更改才会生效。

配置

<configurationRedirection> 元素在 Redirection.config 文件中配置。

特性

属性 说明
enabled 可选布尔属性。

指定是在 Web 服务器上启用还是禁用配置重定向。

默认值为 false
enableUncPolling 可选布尔属性。

如果应使用 UNC 轮询来检查配置文件是否已更新,则为 true;否则,如果应使用更改通知,则为 false。 注意:两个检查之间的时间间隔通过 pollingPeriod 特性配置。

注:IIS 7.5 中添加了此特性。

默认值为 false
password 可选的字符串属性。

指定用户名进行身份验证以访问配置文件存储位置时所需的密码。 这是一个区分大小写的字符串。

注意:为避免在配置文件中存储未加密的密码字符串,请始终使用 AppCmd.exe 或 IIS 管理器输入密码。 如果使用这些管理工具,将密码字符串写入 XML 配置文件之前将对其自动加密。 这比存储未加密的密码具有更好的密码安全性。
path 可选的字符串属性。

指定从中读取配置文件和加密密钥的位置。 可以是网络路径或本地计算机上的文件夹。

没有默认值。
pollingPeriod 可选的 timeSpan 特性。

指定 IIS 检查配置文件是否已更新时两次检查间的时间间隔。 注意:仅当 enableUncPolling 特性设置为 true 时才适用。

注:IIS 7.5 中添加了此特性。

默认值为 00:03:00(三分钟)。
userName 可选的字符串属性。

指定要访问配置文件存储位置的用户名。

没有默认值。

子元素

无。

配置示例

以下代码示例演示如何将 IIS 7 配置为将配置文件和加密密钥共享到网络上的共享目录。

<CONFIGURATION>

   <CONFIGSECTIONS>
      <SECTION name="configurationRedirection" />
   </CONFIGSECTIONS>

   <CONFIGPROTECTEDDATA>
      <PROVIDERS>
         <ADD description="Uses RsaCryptoServiceProvider to encrypt and decrypt" name="IISRsaProvider" type="" keyContainerName="iisConfigurationKey" cspProviderName="" useMachineContainer="true" useOAEP="false" />
      </PROVIDERS>
   </CONFIGPROTECTEDDATA>

   <CONFIGURATIONREDIRECTION enabled="true" path="\\ServerName\ShareName" userName="MyUser" password="[enc:IISRsaProvider:57686f6120447564652c2049495320526f636b73:enc]" />

</CONFIGURATION>

代码示例

以下示例使用 \\ServerName\ShareName 处共享的、导出的配置文件以及使用用户名“MyUser”和密码“P@ssw0rd”来访问共享,以此启用共享配置。

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.GetRedirectionConfiguration();
         ConfigurationSection redirectionSection = config.GetSection("configurationRedirection");

         redirectionSection.Attributes["enabled"].Value = true;
         redirectionSection.Attributes["path"].Value = @"\\ServerName\ShareName";
         redirectionSection.Attributes["userName"].Value = @"MyUser";
         redirectionSection.Attributes["password"].Value = @"P@ssw0rd";

         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.GetRedirectionConfiguration
      Dim redirectionSection As ConfigurationSection = config.GetSection("configurationRedirection")
      redirectionSection.Attributes("enabled").Value = True
      redirectionSection.Attributes("path").Value = "\\ServerName\ShareName"
      redirectionSection.Attributes("userName").Value = "MyUser"
      redirectionSection.Attributes("password").Value = "P@ssw0rd"
      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

try
{
   var config = WScript.CreateObject( "Microsoft.ApplicationHost.WritableAdminManager" );
   config.CommitPath = "MACHINE/REDIRECTION";
   var section = config.GetAdminSection( "configurationRedirection","MACHINE/REDIRECTION" );
   section.Properties.Item( "enabled" ).Value = true;
   section.Properties.Item( "path" ).Value = "\\\\ServerName\\ShareName";
   section.Properties.Item( "userName" ).Value = "MyUser";
   section.Properties.Item( "password" ).Value = "P@ssw0rd";
   config.CommitChanges();
}
catch(e)
{
   WScript.Echo(e.number); 
   WScript.Echo(e.description);
}

VBScript

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

Set configurationRedirection = adminManager.GetAdminSection( "configurationRedirection", _
"MACHINE/REDIRECTION" )

configurationRedirection.Properties.Item( "enabled" ).Value = True
configurationRedirection.Properties.Item( "path" ).Value = "\\ServerName\ShareName"
configurationRedirection.Properties.Item( "userName" ).Value = "MyUser"
configurationRedirection.Properties.Item( "password" ).Value = "P@ssw0rd"

adminManager.CommitChanges