authentication 項目 (ASP.NET 設定結構描述)

設定用於識別檢視 ASP.NET 應用程式使用者的 ASP.NET 驗證配置。

<authentication 
   mode="[Windows|Forms|Passport|None]"
> 
   <forms>...</forms>
   <passport/>
</authentication>

屬性和項目

下列各節將說明屬性、子項目和父項目。

屬性

屬性

描述

mode

必要屬性。

指定應用程式的預設驗證模式。 這個屬性可以是下列其中一個值。

值描述
Windows 指定 Windows 驗證做為預設驗證模式。請搭配此模式使用任何形式的 Microsoft Internet Information Services (IIS) 驗證:基本、摘要、整合式 Windows 驗證 (NTLM/Kerberos) 或憑證。在此情況下,您的應用程式會將驗證責任委派 (Delegate) 給基礎的 IIS。
Forms 指定 ASP.NET 表單架構的驗證做為預設驗證模式。
Passport 指定 Microsoft Passport 驗證做為預設驗證模式。
None 不指定驗證。您的應用程式只能接受匿名使用者,或是會提供自己的驗證之應用程式提供者。

預設值為 Windows。

子項目

項目

描述

forms

設定 ASP.NET 應用程式以進行自訂表單架構驗證。

passport

指定當網頁需要驗證而使用者未使用 Microsoft Passport 網路驗證進行簽入時,做為重新導向目標的網頁。

父項目

項目

描述

configuration

指定 Common Language Runtime 和 .NET Framework 應用程式所使用之每個組態檔中需要的根項目 (Root Element)。

system.web

指定組態檔中 ASP.NET 組態設定的根項目 (Root Element),並包含會設定 ASP.NET Web 應用程式以及控制這些應用程式之行為的組態項目。

備註

authentication 項目會為 ASP.NET 應用程式設定 ASP.NET 驗證配置。 驗證配置會判斷如何識別想要檢視 ASP.NET 應用程式的使用者。 mode 屬性則會指定驗證配置。 如需可用之驗證配置的詳細資訊,請參閱 ASP.NET 驗證

預設組態

下列預設的 authentication 項目不會在 Machine.config 檔或根 Web.config 檔中明確設定。 不過,這是 .NET Framework 2.0 版中應用程式所傳回的預設組態。

<authentication mode="Windows">
   <forms 
      name=".ASPXAUTH" 
      loginUrl="login.aspx" 
      defaultUrl="default.aspx" 
      protection="All" 
      timeout="30" 
      path="/" 
      requireSSL="false" 
      slidingExpiration="true" 
      cookieless="UseDeviceProfile" domain="" 
      enableCrossAppRedirects="false">
      <credentials passwordFormat="SHA1" />
   </forms>
   <passport redirectUrl="internal" />
</authentication>

下列預設 authentication 項目是在 .NET Framework 1.1 版中的 Machine.config 檔案中設定。

<authentication mode="Windows">
   <forms 
      name=".ASPXAUTH" 
      loginUrl="login.aspx" 
      protection="All"  
      timeout="30" 
      path="/" 
      requireSSL="false" 
      slidingExpiration="true">
      <credentials passwordFormat="SHA1"></credentials>
   </forms>
   <passport redirectUrl="internal" />
</authentication>

下列預設 authentication 項目是在 .NET Framework 1.0 版中的 Machine.config 檔案中設定。

<authentication mode="Windows">
   <forms 
      name=".ASPXAUTH" 
      loginUrl="login.aspx" 
      protection="All"  
      timeout="30" 
      path="/" >
      <credentials passwordFormat="SHA1"></credentials>
   </forms>
   <passport redirectUrl="internal" />
</authentication>

範例

下列程式碼範例示範如何設定網站以進行表單架構驗證,指定從用戶端傳輸登入資訊的 Cookie 名稱,以及指定初始驗證失敗時要使用的登入網頁名稱。 您需要包含 authorization 區段,以要求所有使用者提供表單驗證,並拒絕匿名使用者存取網站。

<configuration>
   <system.web>
      <authentication mode="Forms">
         <forms name="401kApp" loginUrl="/login.aspx"/>
      </authentication>
      <authorization>
         <deny users="?"/>
      </authorization>
   </system.web>
</configuration>

項目資訊

組態區段處理常式

AuthenticationSection

組態成員

AuthenticationMode

可設定的位置

Machine.config

根層次的 Web.config

應用程式層級的 Web.config

需求

Microsoft Internet Information Services (IIS) 5.0、5.1 或 6.0 版

.NET Framework 1.0、1.1 或 2.0 版

Microsoft Visual Studio 2003 或 Visual Studio 2005

請參閱

工作

HOW TO:使用位置設定來設定特定的目錄

HOW TO:鎖定 ASP.NET 組態設定

參考

system.web 項目 (ASP.NET 設定結構描述)

驗證的 forms 項目 (ASP.NET 設定結構描述)

驗證的 passport 項目 (ASP.NET 設定結構描述)

configuration 項目 (一般設定結構描述)

System.Configuration

System.Web.Configuration

AuthenticationSection

概念

ASP.NET 組態檔階層架構和繼承

保護 ASP.NET 組態

ASP.NET 組態案例

其他資源

ASP.NET 驗證

一般組態設定 (ASP.NET)

ASP.NET 組態設定

ASP.NET 網站管理

ASP.NET 組態檔

ASP.NET 組態 API