共用方式為


FormsAuthenticationConfiguration 類別

設定 ASP.NET 應用程式的表單驗證。

Syntax

class FormsAuthenticationConfiguration : EmbeddedObject  

方法

這個類別不包含方法。

屬性

下表列出 類別所 FormsAuthenticationConfiguration 公開的屬性。

名稱 描述
Cookieless 讀取/寫入 sint32 列舉,指定表單驗證是否應該使用 Cookie。 可能的值稍後會列在一節中。
Credentials FormsAuthenticationCredentials值,其中包含表單驗證期間要使用的使用者名稱和密碼集合。 注意: 需要安全性時,您應該在資料庫存放區) 中使用替代方式來儲存使用者名稱和密碼 (。 如果您決定使用此集合,您應該在 類別的 FormsAuthenticationCredentials 屬性中 PasswordFormat 指定加密格式。
DefaultUrl 讀取/寫入無空白 string 值,指定在驗證之後導向要求的預設 URL。 預設值為 「default.aspx」。
Domain 讀取/寫入 string 值,指定要以表單驗證 Cookie 傳送的功能變數名稱。 預設值為 ""。 對於表單驗證 Cookie,此設定的優先順序高於HttpCookiesSection類別的 屬性中的 Domain 設定。
EnableCrossAppRedirects 讀取/寫入 boolean 值。 true 如果已驗證的使用者可以重新導向至其他應用程式中的 URL;否則為 false 。 預設值為 false。 如果此屬性為 true ,則會執行重新導向;否則,瀏覽器會重新導向至 屬性中 DefaultUrl 定義的頁面。 注意: 當表單驗證跨多個 ASP.NET 應用程式啟用時,使用者不需要在應用程式之間切換時重新驗證。 如需詳細資訊,請參閱 跨應用程式進行表單驗證
LoginUrl 無空讀取/寫入 string 值,指定使用者未驗證或沒有有效驗證 Cookie 存在時,要求重新導向至的 URL。 預設值為 「login.aspx」。
Name 無空讀取/寫入 string 值,指定要用於要求驗證的 HTTP Cookie 名稱。 預設值為 ".ASPXAUTH"。
Path 無空讀取/寫入 string 值,指定要用於驗證的 HTTP Cookie 路徑。 路徑會隨著驗證 Cookie 本身一起傳輸。 預設值為 「/」,表示 Web 應用程式根目錄。
Protection 讀取/寫入 sint32 值,指定用於 Cookie 的加密方法。 可能的值稍後會列在一節中。
RequireSSL 讀取/寫入 boolean 值。 true 如果驗證需要安全通訊端層 (SSL) 連線,則為 ;否則為 false 。 預設值為 false。 如果此屬性為 true ,Web 應用程式會拒絕所有不使用 SSL 連線的表單驗證要求。
SlidingExpiration 讀取/寫入 boolean 值。 true 如果驗證 Cookie 的到期時間會設定為目前的日期和時間加上 屬性中的 Timeout 值,則為 ,否則為 false 。 預設值為 true

如果 true 為 ,則會在 中的值少於一半 Timeout 且使用者仍在使用應用程式時,自動重設 Cookie 的到期日期和時間。 如果 false 為 ,則 Cookie 會在 屬性中指定的 Timeout 間隔通過之後自動逾時。
Timeout 讀取/寫入 datetime 值,指定驗證到期的時間量。 預設值是 30 分鐘。

子類別

這個類別不包含子類別。

備註

這個類別的實例包含在AuthenticationSection類別的 屬性中 Forms

下表列出 屬性的可能值 Cookieless 。 預設值為 3 (UseDeviceProfile) 。

關鍵字 描述
0 UseUri 指定不論瀏覽器或裝置是否支援 Cookie,呼叫功能都會使用查詢字串來儲存識別碼。
1 UseCookies 指定不論瀏覽器或裝置是否支援 Cookie,Cookie 都會用來保存使用者資料。
2 AutoDetect 指定 ASP.NET 判斷要求瀏覽器或裝置是否支援 Cookie。 如果瀏覽器或裝置支援 Cookie,要求的功能會使用 Cookie 來保存使用者資料;否則,要求功能會使用查詢字串中的識別碼。 如果瀏覽器或裝置支援 Cookie,但 Cookie 目前已停用,要求功能仍會使用 Cookie。
3 UseDeviceProfile 指定 ASP.NET 判斷是否根據 CookiesSystem.Web.Configuration.HttpCapabilitiesBase 類別的 屬性使用 Cookie。 如果設定指出瀏覽器或裝置支援 Cookie,要求功能會使用 Cookie;否則,要求功能會使用查詢字串中的識別碼。

下表列出 屬性的可能值 Protection 。 預設值為 0 (All) 。

關鍵字 描述
0 All 指定應用程式會同時使用資料驗證和加密來協助保護 Cookie。 此選項使用 MachineKeySection 類別中指定的資料驗證演算法。 應用程式會使用三重資料加密標準 (Triple DES) 進行加密,如果金鑰長度至少為 48 個位元組,則為 。 注意: 這是建議的設定。 若要改善 Cookie 的保護,您可能也想要將 RequireSSL 屬性設定為 true
1 None 指定已停用加密和驗證。 此設定適用于只有個人化使用 Cookie 的較弱安全性需求的網站。 您應該避免以這種方式使用 Cookie;不過,使用.NET Framework啟用個人化是最不耗用資源的方式。
2 Encryption 指定使用 Triple DES 或 DES 加密 Cookie。 使用此設定時,不會對 Cookie 執行資料驗證,這會使這些 Cookie 受到純文字安全性攻擊。
3 Validation 指定應用程式將使用驗證配置來驗證加密 Cookie 的內容尚未在傳輸中變更。 Cookie 的建立是藉由串連驗證金鑰和 Cookie 資料,計算訊息驗證程式碼 (Message Authentication Code,MAC),並將 MAC 附加於外送的 Cookie。

範例

下列範例會顯示預設網站的表單驗證設定。

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Get the authentication section.  
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")  
oSite.GetSection "AuthenticationSection", oAuthSection  
  
' Assign the Forms property to a variable.  
Set oFormsAuthConfig = oAuthSection.Forms  
  
' Display the Forms authentication settings.  
WScript.Echo "Forms Authentication Settings"  
WScript.Echo "-----------------------------"  
  
WScript.Echo "Cookieless: [ " & _  
    CookielessText(oFormsAuthConfig.Cookieless)& " ]"  
  
WScript.Echo "Default Url: [ " & _  
    oFormsAuthConfig.DefaultUrl& " ]"  
  
WScript.Echo "Domain: [ " & oFormsAuthConfig.Domain& " ]"  
  
WScript.Echo "EnableCrossAppRedirects: [ " & _  
    oFormsAuthConfig.EnableCrossAppRedirects& " ]"  
  
WScript.Echo "LoginUrl: [ " & _  
    oFormsAuthConfig.LoginUrl & " ]"  
  
WScript.Echo "Name: [ " & oFormsAuthConfig.Name& " ]"  
  
WScript.Echo "Path: [ " & oFormsAuthConfig.Path& " ]"  
  
WScript.Echo "Protection: [ " & _  
    ProtectionText(oFormsAuthConfig.Protection)& " ]"  
  
WScript.Echo "RequireSSL: [ " & _  
    oFormsAuthConfig.RequireSSL& " ]"  
  
WScript.Echo "SlidingExpiration: [ " & _  
    oFormsAuthConfig.SlidingExpiration& " ]"  
  
WScript.Echo "Timeout: [ " & oFormsAuthConfig.Timeout& " ]"  
  
' Call a sub to display the credentials information.  
DisplayCredentials(oFormsAuthConfig.Credentials)  
  
' Convert the Cookieless enumeration values to text.  
Function CookielessText(enumValue)  
    Select Case enumValue  
        Case 0  
            CookielessText = "UseUri"  
        Case 1  
            CookielessText = "UseCookies"  
        Case 2  
            CookielessText = "AutoDetect"  
        Case 3  
            CookielessText = "UseDeviceProfile"  
        Case Else  
            CookielessText = "Undefined enumeration value."  
    End Select  
End Function  
  
' Convert the Protection enumeration values to text.  
Function ProtectionText(enumValue)  
    Select Case enumValue  
        Case 0  
            ProtectionText = "All"  
        Case 1  
            ProtectionText = "None"  
        Case 2  
            ProtectionText = "Encryption"  
        Case 3  
            ProtectionText = "Validation"  
        Case Else  
            ProtectionText = "Undefined enumeration value."  
    End Select  
End Function  
  
' Display the Forms authentication credentials.  
Sub DisplayCredentials(FA_Credentials)  
    WScript.Echo vbCrLf & "Forms Authentication Credentials"  
    WScript.Echo "--------------------------------"  
  
    ' Display the password encryption format.  
    WScript.Echo "Password Format: " & _  
        PwdFormatText(FA_Credentials.PasswordFormat) & VbCrLf  
  
    ' Display the Forms authentication users and passwords.  
    For Each FormsAuthUser In FA_Credentials.Credentials  
        WScript.Echo "    Name: [ " & FormsAuthUser.Name & " ]"  
        WScript.Echo "Password: [ " & _  
            FormsAuthUser.Password& " ]"  
        WScript.Echo  
    Next  
End Sub  
  
' Convert the PasswordFormat enumeration values to text.  
Function PwdFormatText(enumValue)  
    Select Case enumValue  
        Case 0  
            PwdFormatText = "Clear"  
        Case 1  
            PwdFormatText = "SHA1"  
        Case 2  
            PwdFormatText = "MD5"  
        Case Else  
            PwdFormatText = "Undefined enumeration value."  
    End Select  
End Function  
  

繼承階層架構

EmbeddedObject

FormsAuthenticationConfiguration

規格需求

類型 Description
Client - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8上的 IIS 8.0
- Windows 10上的 IIS 10.0
伺服器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016上的 IIS 10.0
產品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 檔案 WebAdministration.mof

另請參閱

System.Web.Configuration.AuthenticationModeSystem.Web.Configuration.FormsAuthenticationConfigurationSystem.Web.Configuration.HttpCapabilitiesBaseAuthenticationSection 類別
EmbeddedObject 類別
FormsAuthenticationCredentials 類別
FormsAuthenticationUser 類別
MachineKeySection 類別
跨應用程式的表單驗證
CIM_DATETIME