共用方式為


匿名驗證 < 匿名驗證>

概觀

元素 <anonymousAuthentication> 控制 Internet Information Services (IIS) 7 如何處理匿名使用者的要求。 您可以修改 元素 <anonymousAuthentication> 以停用匿名驗證,也可以設定 Internet Information Services (IIS) ,以使用自訂使用者帳戶來處理匿名要求。

匿名驗證可讓使用者存取您網站或 FTP 網站的公用區域,而不會提示他們輸入使用者名稱或密碼。 根據預設,IIS 7.0 中引進的 IUSR 帳戶會取代 IIS 6.0 IUSR_computername 帳戶,以允許匿名存取。 應用程式是一組檔案,可傳遞內容或透過通訊協定提供服務,例如 HTTP。 當您在 IIS 中建立應用程式時,應用程式的路徑會成為網站 URL 的一部分。

根據預設,IIS 7 會使用匿名驗證。 您必須針對您想要啟用基本或Windows 驗證等其他驗證方法的任何網站、Web 應用程式或 Web 服務停用匿名驗證。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <anonymousAuthentication>
IIS 8.5 未在 IIS 8.5 中修改專案 <anonymousAuthentication>
IIS 8.0 未在 IIS 8.0 中修改專案 <anonymousAuthentication>
IIS 7.5 未在 IIS 7.5 中修改專案 <anonymousAuthentication>
IIS 7.0 元素 <anonymousAuthentication> 是在 IIS 7.0 中引進。
IIS 6.0 元素 <anonymousAuthentication> 會取代 IIS 6.0 AuthFlagsAnonymousUserNameAnonymousUserPassword Metabase 屬性。

安裝程式

元素 <anonymousAuthentication> 包含在 IIS 7 的預設安裝中。

作法

如何停用匿名驗證

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

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

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
    • 如果您使用 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) Manager
  2. 在 [ 連線 ] 窗格中,展開伺服器名稱、展開 [網站],然後移至您要設定之階層窗格中的層級,然後按一下網站或 Web 應用程式。

  3. 捲動至 [首頁] 窗格中的 [安全性] 區段,然後按兩下 [驗證]。

  4. 在 [驗證] 窗格中,選取 [匿名驗證],然後按一下 [動作] 窗格中的 [停用]。
    已選取 [匿名驗證] 的 [驗證] 窗格螢幕擷取畫面。

如何從 IUSR 帳戶變更匿名驗證認證

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

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

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
    • 如果您使用 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) Manager
  2. 在 [ 連線 ] 窗格中,展開伺服器名稱、展開 [網站],然後流覽至您要設定之階層窗格中的層級,然後按一下網站或 Web 應用程式。

  3. 捲動至 [首頁] 窗格中的 [安全性] 區段,然後按兩下 [驗證]。

  4. 在 [驗證] 窗格中,選取 [匿名驗證],然後按一下 [動作] 窗格中的 [編輯...]。

  5. 在 [ 編輯匿名驗證認證 ] 對話方塊中,執行下列其中一項:

    • 選取 [應用程式集區身分識別 ] 以使用應用程式集區的身分識別集,然後按一下 [ 確定]。
      將匿名使用者身分識別設定為應用程式集區身分識別的螢幕擷取畫面。

    • 按一下 [設定...],然後在 [ 設定認證 ] 對話方塊中,于 [ 使用者名稱 ] 方塊中輸入帳戶的使用者名稱,在 [ 密碼 ] 和 [ 確認密碼 ] 方塊中輸入帳戶的密碼,按一下 [ 確定],然後再按一下 [ 確定 ]。
      空白 [設定認證] 對話方塊的螢幕擷取畫面。

      注意

      如果您使用此程式,則只會授與 IIS 伺服器電腦上的新帳戶最低許可權。

組態

元素 <anonymousAuthentication> 可在Web.config檔案的月臺和應用層級設定。

屬性

屬性 描述
enabled 選擇性的 Boolean 屬性。

指定是否啟用匿名驗證。

預設值是 true
logonMethod 選擇性列舉屬性。

logonMethod屬性可以是下列其中一個可能的值。 預設值為 ClearText
描述
Batch 此登入類型適用于批次伺服器,其中進程可能代表使用者執行,而不需要該使用者的直接介入。

數值為 1
ClearText 此登入類型會保留驗證套件中的名稱和密碼,這可讓伺服器在模擬用戶端時連線到其他網路伺服器。

數值為 3
Interactive 此登入類型適用于將以互動方式使用電腦的使用者。

數值為 0
Network 此登入類型適用于高效能伺服器,以驗證純文字密碼。 此登入類型不會快取認證。

數值為 2
password 選用的 String 屬性。

指定匿名驗證的密碼。

注意: 若要避免在組態檔中儲存未加密的密碼字串,請一律使用 AppCmd.exe 或 IIS 管理員來輸入密碼。 如果您使用這些管理工具,密碼字串會在將密碼字串寫入 XML 組態檔之前自動加密。 這比儲存未加密的密碼提供更好的密碼安全性。
username 選用的 String 屬性。

指定匿名驗證的使用者名稱。 如果您將此值保留空白 (即 username=「」) ,匿名驗證會使用應用程式集區身分識別來驗證匿名使用者。

預設值是 IUSR

子元素

無。

組態範例

下列組態範例會設定 IIS 7 網站或 Web 應用程式的匿名驗證,以在 Web 服務器上使用本機帳戶。 (IIS 7 會自動使用 AES 加密來加密 password.)

<security> <authentication>
   <anonymousAuthentication
      userName="User1"
      password="[enc:AesProvider:57686f6120447564652c2049495320526f636b73:enc]" />
   </authentication>
</security>

範例程式碼

下列範例會啟用匿名驗證,並將用於匿名驗證的預設使用者名稱和密碼變更為名為 IUSR 的帳戶,以及 P@ssw0rd的密碼。

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /userName:"IUSR" /commit:apphost
appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /password:"P@ssw0rd" /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 anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
         anonymousAuthenticationSection["enabled"] = true;
         anonymousAuthenticationSection["userName"] = @"IUSR";
         anonymousAuthenticationSection["password"] = @"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.GetApplicationHostConfiguration
      Dim anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso")
      anonymousAuthenticationSection("enabled") = True
      anonymousAuthenticationSection("userName") = "IUSR"
      anonymousAuthenticationSection("password") = "P@ssw0rd"
      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

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

var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
anonymousAuthenticationSection.Properties.Item("enabled").Value = true;
anonymousAuthenticationSection.Properties.Item("userName").Value = "IUSR";
anonymousAuthenticationSection.Properties.Item("password").Value = "P@ssw0rd";

adminManager.CommitChanges();

VBScript

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

Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
anonymousAuthenticationSection.Properties.Item("enabled").Value = True
anonymousAuthenticationSection.Properties.Item("userName").Value = "IUSR"
anonymousAuthenticationSection.Properties.Item("password").Value = "P@ssw0rd"

adminManager.CommitChanges()