共用方式為


用戶端憑證對應驗證 < 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 在 IIS 8.0 中未修改專案 <clientCertificateMappingAuthentication>
IIS 7.5 <clientCertificateMappingAuthentication> 在 IIS 7.5 中修改專案。
IIS 7.0 元素 <clientCertificateMappingAuthentication><authentication> 元素是在 IIS 7.0 中引進。
IIS 6.0 N/A

安裝程式

專案 <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 Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [ 用戶端憑證對應驗證]。
    已展開 [萬維網服務] 窗格的螢幕擷取畫面,並已選取 [用戶端憑證對應驗證]。
  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 Information Services],然後選取 [用戶端憑證對應驗證],然後按一下 [ 確定]。
    已展開 [Internet Information Services] 窗格的螢幕擷取畫面,並醒目提示 [用戶端憑證對應驗證]。

作法

如何啟用伺服器的用戶端憑證對應驗證

  1. (IIS) 管理員開啟 Internet Information Services

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

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services] ([IIS) 管理員]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [ 系統管理工具],然後按兩下 [Internet Information Services] ([IIS) 管理員]。
    • 如果您使用 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 選擇性的 Boolean 屬性。

指定是否已啟用使用 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()