客户端证书映射身份验证 <clientCertificateMappingAuthentication>

概述

<clientCertificateMappingAuthentication><authentication>元素的元素指定是否为 Internet Information Services (IIS) 7 启用使用 Active Directory 的客户端证书映射。

注意

使用 Active Directory 的客户端证书映射身份验证不同于 使用 IIS 的客户端证书映射身份验证 ,方式如下:

  • 使用 Active Directory 的客户端证书映射身份验证 - 此方法要求 IIS 7 服务器是 Active Directory 域的成员,用户帐户存储在 Active Directory 中。 由于对 Active Directory 服务器的往返,客户端证书身份验证的此方法降低了性能。
  • IIS 客户端证书映射身份验证 - 此方法不需要 Active Directory,因此适用于独立服务器。 此客户端证书身份验证方法提高了性能,但需要更多配置,并且需要访问客户端证书才能创建映射。

有关详细信息,请参阅 Microsoft TechNet 网站上的 IIS 7.0 中配置身份验证

兼容性

版本 备注
IIS 10.0 <clientCertificateMappingAuthentication> 在 IIS 10.0 中修改该元素。
IIS 8.5 <clientCertificateMappingAuthentication> 在 IIS 8.5 中修改该元素。
IIS 8.0 <clientCertificateMappingAuthentication> 在 IIS 8.0 中修改该元素。
IIS 7.5 <clientCertificateMappingAuthentication> 元素未在 IIS 7.5 中修改。
IIS 7.0 <clientCertificateMappingAuthentication> 元素的 <authentication> 元素是在 IIS 7.0 中引入的。
IIS 6.0 不适用

设置

<clientCertificateMappingAuthentication> 元素在 IIS 7 及更高版本的默认安装上不可用。 若要安装它,请使用以下步骤。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在任务栏上,单击“服务器管理器”。
  2. 服务器管理器中,单击“管理”菜单,然后单击“添加角色和功能”。
  3. “添加角色和功能 ”向导中,单击“ 下一步”。 选择安装类型,然后单击“ 下一步”。 选择目标服务器,然后单击“ 下一步”。
  4. “服务器角色” 页上,展开 “Web 服务器” (IIS) ,展开 “Web 服务器”,展开 “安全性”,然后选择“ 客户端证书映射身份验证”。 单击“下一步”。
    “Web 服务器和安全”窗格的图像展开,其中选择了“客户端证书映射身份验证”。 .
  5. 在“选择功能”页上,单击“下一步”
  6. “确认安装选择”页上,单击“安装”
  7. 在“结果”页面中单击“关闭”

Windows 8或Windows 8.1

  1. “开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击控制面板
  2. 控制面板中,单击“程序和功能”,然后单击“打开或关闭 Windows 功能”。
  3. 展开 Internet 信息服务,展开 万维网服务,展开 “安全性”,然后选择 “客户端证书映射身份验证”。
    已展开的万维网服务窗格的屏幕截图,并选择了“客户端证书映射身份验证”。
  4. 单击 “确定”
  5. 单击“关闭”。

Windows Server 2008 或 Windows Server 2008 R2

  1. 在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
  2. “服务器管理器层次结构”窗格中,展开“角色”,然后单击“Web 服务器” (IIS)
  3. “Web 服务器 (IIS) ”窗格中,滚动到 “角色服务 ”部分,然后单击“ 添加角色服务”。
  4. “添加角色服务向导”的“选择角色服务”页上,选择“客户端证书映射身份验证”,然后单击“下一步”。
    “选择角色服务”页的图像,其中展开了“安全”窗格,并选择了“客户端证书映射身份验证”。
  5. “确认安装选择”页中,单击“安装”
  6. 在“结果”页面中单击“关闭”

Windows Vista 或 Windows 7

  1. 在任务栏上,单击“开始”,然后单击控制面板
  2. 控制面板中,单击“程序和功能”,然后单击“打开或关闭 Windows 功能”。
  3. 展开 Internet 信息服务,然后选择 “客户端证书映射身份验证”,然后单击“ 确定”。
    “Internet Information Services”窗格的屏幕截图,其中突出显示了“客户端证书映射身份验证”。

操作方式

如何为服务器启用客户端证书映射身份验证

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

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

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

      • 按住 Windows 键,按字母 X,然后单击控制面板
      • 单击 “管理工具”,然后双击“ Internet Information Services” (IIS) Manager
    • 如果使用 Windows Server 2008 或 Windows Server 2008 R2:

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

      • 在任务栏上,单击“开始”,然后单击控制面板
      • 双击 “管理工具”,然后双击“ Internet Information Services” (IIS) 管理器
  2. “连接” 窗格中,单击服务器名称。

  3. 在服务器的 “主页 ”窗格中,双击“ 身份验证”。
    “服务器主页”窗格的屏幕截图,其中突出显示了“身份验证”。

  4. “身份验证”页上,单击“操作”窗格中的“启用”。
    “身份验证”页中的“操作”窗格的图像,其中突出显示了 Active Directory 客户端证书身份验证选项。

配置

属性

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

指定是否启用使用 Active Directory 的客户端证书映射身份验证。 若要使此设置生效,必须使用 IIS 管理器设置此属性。 如果使用任何其他方法来设置此属性,则必须重启 Web 服务器,使设置生效。

默认值为 false

子元素

无。

配置示例

以下配置示例使用 Active Directory 为默认网站启用客户端证书映射身份验证,并将站点配置为要求 SSL 并协商客户端证书。

<location path="Default Web Site">
   <system.webServer>
      <security>
         <access sslFlags="Ssl, SslNegotiateCert" />
          <authentication>
            <windowsAuthentication enabled="false" />
            <anonymousAuthentication enabled="false" />
            <digestAuthentication enabled="false" />
            <basicAuthentication enabled="false" />
            <clientCertificateMappingAuthentication enabled="true" />
         </authentication>
     </security>
   </system.webServer>
</location>

代码示例

以下代码示例使用 Active Directory 为默认网站启用客户端证书映射身份验证,并将站点配置为要求 SSL 并协商客户端证书。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/security/authentication/clientCertificateMappingAuthentication /enabled:"True" /commit:apphost

appcmd.exe set config "Default Web Site" -section:system.webServer/security/access /sslFlags:"Ssl, SslNegotiateCert" /commit:apphost

注意

在使用AppCmd.exe配置这些设置时,必须确保将 提交 参数 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 clientCertificateMappingAuthenticationSection = config.GetSection("system.webServer/security/authentication/clientCertificateMappingAuthentication", "Default Web Site");
         clientCertificateMappingAuthenticationSection["enabled"] = true;

         ConfigurationSection accessSection = config.GetSection("system.webServer/security/access", "Default Web Site");
         accessSection["sslFlags"] = @"Ssl, SslNegotiateCert";

         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 clientCertificateMappingAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/clientCertificateMappingAuthentication", "Default Web Site")
      clientCertificateMappingAuthenticationSection("enabled") = True

      Dim accessSection As ConfigurationSection = config.GetSection("system.webServer/security/access", "Default Web Site")
      accessSection("sslFlags") = "Ssl, SslNegotiateCert"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

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

var clientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/clientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site");
clientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = true;

var accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site");
accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert";

adminManager.CommitChanges();

VBScript

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

Set clientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/clientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site")
clientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = True

Set accessSection = adminManager.GetAdminSection("system.webServer/security/access", "MACHINE/WEBROOT/APPHOST/Default Web Site")
accessSection.Properties.Item("sslFlags").Value = "Ssl, SslNegotiateCert"

adminManager.CommitChanges()