摘要式驗證摘要驗證 <>
概觀
元素 <digestAuthentication>
包含 Internet Information Services (IIS) 7 摘要式驗證模組的組態設定。 您可以設定這個專案來啟用或停用摘要式驗證,並選擇性地指定摘要驗證領域。
摘要式驗證不如基本驗證廣泛使用,但對於基本驗證或Windows 驗證有一些不同的優點。 透過非加密通訊方式使用基本驗證的主要缺點是,用戶端的使用者名稱和密碼會以 base-64 編碼的純文字訊息形式傳送,讓惡意使用者很容易地竊聽通訊並擷取使用者名稱和密碼。 Windows 驗證可透過各種安全性選項解決此問題,但Windows 驗證通常無法在網際網路環境中運作。
摘要式驗證會以下列方式解決上述這兩項限制:
- 不同于基本驗證所使用的純文字配置,摘要式驗證會讓用戶端透過通道傳送用戶端資訊的雜湊,因此用戶端的使用者名稱和密碼永遠不會透過網路傳送。
- 摘要式驗證可透過網際網路運作良好,讓摘要式驗證更適合該環境,而不是Windows 驗證。
注意
摘要式驗證只會保護用戶端的使用者名稱和密碼 - HTTP 通訊主體仍為純文字。 若要保護您的通訊主體,您應該使用安全通訊端層 (SSL) 。
相容性
版本 | 備註 |
---|---|
IIS 10.0 | 在 <digestAuthentication> IIS 10.0 中未修改專案。 |
IIS 8.5 | 未 <digestAuthentication> 在 IIS 8.5 中修改專案。 |
IIS 8.0 | 在 IIS 8.0 中未修改專案 <digestAuthentication> 。 |
IIS 7.5 | 未 <digestAuthentication> 在 IIS 7.5 中修改專案。 |
IIS 7.0 | 專案 <digestAuthentication> 是在 IIS 7.0 中引進的。 |
IIS 6.0 | 元素 <digestAuthentication> 會取代 IIS 6.0 AuthType 和 AuthFlags 中繼基底屬性的部分。 |
安裝程式
IIS 7 和更新版本的預設安裝不包含摘要式驗證角色服務。 若要在 IIS 7 和更新版本上使用摘要式驗證,您必須安裝角色服務、停用網站或應用程式的匿名驗證,然後啟用網站或應用程式的摘要驗證。
若要安裝摘要式驗證角色服務,請使用下列步驟。
Windows Server 2012 或 Windows Server 2012 R2
- 在工作列上,按一下 [伺服器管理員]。
- 在伺服器管理員中,按一下 [管理]功能表,然後按一下 [新增角色和功能]。
- 在 [ 新增角色和功能 精靈] 中,按 [下一步]。 選取安裝類型,然後按 [ 下一步]。 選取目的地伺服器,然後按 [ 下一步]。
- 在 [ 伺服器角色] 頁面上,依序展開 [Web 服務器] ([IIS) ]、[ Web 服務器]、[ 安全性] 和 [ 摘要式驗證]。 按一下 [下一步] 。
. - 在 [選取功能] 頁面上,按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows 8 或Windows 8.1
- 在 [開始] 畫面上,將指標全部移至左下角,以滑鼠右鍵按一下 [開始] 按鈕,然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性],然後選取 [ 摘要式驗證]。
- 按一下 [確定]。
- 按一下 [關閉] 。
Windows Server 2008 或 Windows Server 2008 R2
- 在工作列上,按一下 [開始],指向 [系統管理工具],然後按一下[伺服器管理員]。
- 在[伺服器管理員階層] 窗格中,展開 [角色],然後按一下 [Web 服務器] (IIS) 。
- 在 [Web 服務器 (IIS) ] 窗格中,捲動至 [ 角色服務 ] 區段,然後按一下 [ 新增角色服務]。
- 在 [新增角色服務精靈] 的 [選取角色服務] 頁面上,選取[摘要式驗證],然後按 [下一步]。
- 在 [確認安裝選項] 頁面上,按一下 [安裝]。
- 在 [結果] 頁面上,按一下 [關閉]。
Windows Vista 或 Windows 7
- 在工作列上,按一下 [開始],然後按一下[主控台]。
- 在主控台中,按一下 [程式和功能],然後按一下 [開啟或關閉 Windows 功能]。
- 依 序展開 [Internet Information Services]、[ 萬維網服務]、[ 安全性]、選取 [ 摘要式驗證],然後按一下 [ 確定]。
作法
如何啟用摘要式驗證並停用匿名驗證
(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) 管理員]。
在 [ 連線 ] 窗格中,展開伺服器名稱、 [月臺],然後按一下您要啟用基本驗證的網站、應用程式或 Web 服務。
在 [ 驗證] 窗格中,選取 [摘要式驗證],然後在 [ 動作 ] 窗格中,按一下 [ 啟用]。
組態
專案 <digestAuthentication>
可在月臺、應用程式、虛擬目錄和 URL 層級設定。 安裝角色服務之後,IIS 7 會將下列組態設定認可至ApplicationHost.config檔案。
<digestAuthentication enabled='false' />
屬性
屬性 | 描述 |
---|---|
enabled |
選擇性的 Boolean 屬性。 指定是否啟用摘要式驗證。 預設值是 false 。 |
realm |
選擇性字串屬性。 指定摘要式驗證的領域。 |
子元素
無。
組態範例
下列組態範例會啟用網站、Web 應用程式或 Web 服務的摘要式驗證。 根據預設,這些設定必須包含在您的ApplicationHost.config檔案中,而且您必須將它們包含在 元素中 <location>
,並使用 path 屬性來定義您要套用驗證設定的網站或應用程式。
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<digestAuthentication enabled="true" />
</authentication>
</security>
範例程式碼
下列範例會啟用網站的摘要式驗證。
AppCmd.exe
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/digestAuthentication /enabled:"True" /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 digestAuthenticationSection = config.GetSection("system.webServer/security/authentication/digestAuthentication", "Contoso");
digestAuthenticationSection["enabled"] = true;
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 digestAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/digestAuthentication", "Contoso")
digestAuthenticationSection("enabled") = True
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var digestAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/digestAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
digestAuthenticationSection.Properties.Item("enabled").Value = true;
adminManager.CommitChanges();
VBScript
Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set digestAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/digestAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
digestAuthenticationSection.Properties.Item("enabled").Value = True
adminManager.CommitChanges()