共用方式為


一對一對應 < oneToOneMappings>

概觀

元素 <oneToOneMappings><iisClientCertificateMappingAuthentication> 元素會以一對一為基礎,將個別用戶端憑證對應至個別使用者帳戶。 這些一對一憑證對應可用來取代較常用的驗證方法,例如Windows 驗證基本驗證

注意

一對一憑證對應與 多對一 憑證對應不同,這可將多個憑證對應至單一使用者帳戶。

相容性

版本 備註
IIS 10.0 <oneToOneMappings> IIS 10.0 中未修改專案。
IIS 8.5 <oneToOneMappings> 在 IIS 8.5 中修改專案。
IIS 8.0 在 IIS 8.0 中未修改專案 <oneToOneMappings>
IIS 7.5 <oneToOneMappings> 在 IIS 7.5 中修改專案。
IIS 7.0 元素 <oneToOneMappings><iisClientCertificateMappingAuthentication> 元素是在 IIS 7.0 中引進。
IIS 6.0 元素 <oneToOneMappings> 會取代 IIS 6.0 IIsCertMapper Metabase 物件。

安裝程式

專案 <iisClientCertificateMappingAuthentication> 無法在 IIS 7 和更新版本的預設安裝上使用。 若要安裝,請使用下列步驟。

Windows Server 2012 或 Windows Server 2012 R2

  1. 在工作列上,按一下 [伺服器管理員]
  2. 伺服器管理員中,按一下 [管理]功能表,然後按一下 [新增角色和功能]。
  3. 在 [ 新增角色和功能 精靈] 中,按 [下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
  4. 在 [ 伺服器角色] 頁面上,依序展開 [Web 服務器] ([IIS) ]、[ 網頁伺服器]、[ 安全性] 和 [ IIS 用戶端憑證對應驗證]。 按一下 [下一步] 。
    顯示針對 Windows Server 2012 選取 [I I S 用戶端憑證對應驗證] 的螢幕擷取畫面。 .
  5. 在 [選取功能] 頁面上,按 [下一步]
  6. 在 [確認安裝選項] 頁面上,按一下 [安裝]
  7. 在 [結果] 頁面上,按一下 [關閉]

Windows 8 或Windows 8.1

  1. 在 [開始] 畫面上,將指標全部移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
  3. 序展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [IIS 用戶端憑證對應驗證]。
    顯示針對 Windows 8 選取 [I I S 用戶端憑證對應驗證] 的螢幕擷取畫面。
  4. 按一下 [確定]。
  5. 按一下 [關閉] 。

Windows Server 2008 或 Windows Server 2008 R2

  1. 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
  2. [伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS)
  3. [Web 服務器 (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
  4. 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[IIS 用戶端憑證對應驗證],然後按 [下一步]。
    顯示針對 Windows Server 2008 選取 [I I S 用戶端憑證對應驗證] 的螢幕擷取畫面。
  5. 在 [確認安裝選項] 頁面上,按一下 [安裝]
  6. 在 [結果] 頁面上,按一下 [關閉]

Windows Vista 或 Windows 7

  1. 在工作列上,按一下 [開始],然後按一下[主控台]。
  2. 主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
  3. 展開 [Internet Information Services],然後選取 [IIS 用戶端憑證對應驗證],然後按一下 [ 確定]。
    顯示針對 Windows Vista 或 Windows 7 選取 [I I S 用戶端憑證對應驗證] 的螢幕擷取畫面。

作法

沒有使用者介面可用於設定 IIS 7 的 IIS 用戶端憑證對應驗證。 如需如何以程式設計方式設定 IIS 用戶端憑證對應驗證的範例,請參閱本檔的程式 代碼範例 一節。

組態

屬性

無。

子元素

元素 描述
add 選擇性項目。

將一對一對應加入至一對一對應集合。
clear 選擇性項目。

從一對一對應集合中移除一對一對應的所有參考。

組態範例

下列設定範例會使用預設網站的一對一憑證對應來啟用 IIS 用戶端憑證對應驗證、為使用者帳戶建立單對一憑證對應,並設定網站要求 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" />
            <iisClientCertificateMappingAuthentication enabled="true"
                  oneToOneCertificateMappingsEnabled="true">
               <oneToOneMappings>
                  <add enabled="true"
                     userName="administrator"
                     password="[enc:57686f6120447564652c2049495320526f636b73:enc]"
                     certificate="Base64-Encoded-Certificate-Data" />
               </oneToOneMappings>
            </iisClientCertificateMappingAuthentication>
         </authentication>
      </security>
   </system.webServer>
</location>

如何從用戶端憑證擷取 Base-64 編碼字串

注意

若要擷取本主題中所有範例的 Base-64 編碼憑證資料,您可以使用下列步驟匯出憑證:

  1. 按一下 [開始],然後按一下 [ 執行]。

  2. 輸入 MMC,然後按一下 [ 確定]。

  3. 當 Microsoft Management Console 開啟時,按一下 [ 檔案],然後按一下 [ 新增/移除嵌入式管理單元]。

  4. 在 [ 新增或移除嵌入式管理單元] 對話方塊中:

    • 醒目提示可用嵌入式管理單元清單中的 [憑證 ],然後按一下 [ 新增]。
    • 選擇管理 [我的使用者帳戶] 的憑證,然後按一下 [ 完成]。
    • 按一下 [確定] ,關閉對話方塊。
  5. 在 Microsoft Management Console 中:

    • 展開 [憑證 - 目前使用者]、[ 個人] 和 [ 憑證]。
    • 在憑證清單中,以滑鼠右鍵按一下您要匯出的憑證,然後按一下 [ 所有工作],然後按一下 [ 匯出]。
  6. 當 [ 憑證匯出精靈 ] 開啟時:

    • 按一下 [下一步] 。
    • 選擇 [否],不要匯出私密金鑰,然後按 [ 下一步]。
    • 選擇 Base-64 編碼的 X.509 9 (。CER) 匯出格式,然後按 [下一步]。
    • 選擇將憑證儲存到桌面作為 MyCertificate.cer,然後按 [ 下一步]。
    • 按一下 [完成] ;您應該會看到一個對話方塊,指出匯出成功。
  7. 關閉 Microsoft Management Console。

  8. 開啟您使用 Windows 記事本匯出的 MyCertificate.cer 檔案:

    • 從文字開頭移除 「-----BEGIN CERTIFICATE-----」。
    • 從文字結尾移除 「-----END CERTIFICATE-----」。
    • 將所有行串連成單行文字 - 這是您將用於本主題中所有範例的 Base-64 編碼憑證資料。

範例程式碼

下列程式碼範例會使用預設網站的一對一憑證對應來啟用 IIS 用戶端憑證對應驗證、建立使用者帳戶的單一對一憑證對應,以及設定網站以要求 SSL 和交涉用戶端憑證。

注意

若要擷取下列程式碼範例的 Base-64 編碼憑證資料,您可以使用本檔的 [設定 詳細 資料] 區段中所列的步驟匯出憑證。

AppCmd.exe

注意

由於憑證字串中無法由AppCmd.exe剖析的字元,因此您不應該使用AppCmd.exe來設定 IIS 一對一憑證對應。

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 iisClientCertificateMappingAuthenticationSection = config.GetSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "Default Web Site");
         iisClientCertificateMappingAuthenticationSection["enabled"] = true;
         iisClientCertificateMappingAuthenticationSection["oneToOneCertificateMappingsEnabled"] = true;

         ConfigurationElementCollection oneToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("oneToOneMappings");
         ConfigurationElement addElement = oneToOneMappingsCollection.CreateElement("add");
         addElement["enabled"] = true;
         addElement["userName"] = @"Username";
         addElement["password"] = @"Password";
         addElement["certificate"] = @"Base-64-Encoded-Certificate-Data";
         oneToOneMappingsCollection.Add(addElement);

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

      Dim oneToOneMappingsCollection As ConfigurationElementCollection = iisClientCertificateMappingAuthenticationSection.GetCollection("oneToOneMappings")
      Dim addElement As ConfigurationElement = oneToOneMappingsCollection.CreateElement("add")
      addElement("enabled") = True
      addElement("userName") = "Username"
      addElement("password") = "Password"
      addElement("certificate") = "Base-64-Encoded-Certificate-Data"
      oneToOneMappingsCollection.Add(addElement)

      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 iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site");
iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = true;
iisClientCertificateMappingAuthenticationSection.Properties.Item("oneToOneCertificateMappingsEnabled").Value = true;

var oneToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("oneToOneMappings").Collection;
var addElement = oneToOneMappingsCollection.CreateNewElement("add");
addElement.Properties.Item("enabled").Value = true;
addElement.Properties.Item("userName").Value = "Username";
addElement.Properties.Item("password").Value = "Password";
addElement.Properties.Item("certificate").Value = "Base-64-Encoded-Certificate-Data";
oneToOneMappingsCollection.AddElement(addElement);

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 iisClientCertificateMappingAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/iisClientCertificateMappingAuthentication", "MACHINE/WEBROOT/APPHOST/Default Web Site")
iisClientCertificateMappingAuthenticationSection.Properties.Item("enabled").Value = True
iisClientCertificateMappingAuthenticationSection.Properties.Item("oneToOneCertificateMappingsEnabled").Value = True

Set oneToOneMappingsCollection = iisClientCertificateMappingAuthenticationSection.ChildElements.Item("oneToOneMappings").Collection
Set addElement = oneToOneMappingsCollection.CreateNewElement("add")
addElement.Properties.Item("enabled").Value = True
addElement.Properties.Item("userName").Value = "Username"
addElement.Properties.Item("password").Value = "Password"
addElement.Properties.Item("certificate").Value = "Base-64-Encoded-Certificate-Data"
oneToOneMappingsCollection.AddElement(addElement)

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

adminManager.CommitChanges()