AuthenticationSection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定 Web 應用程式的驗證。 此類別無法獲得繼承。
public ref class AuthenticationSection sealed : System::Configuration::ConfigurationSection
public sealed class AuthenticationSection : System.Configuration.ConfigurationSection
type AuthenticationSection = class
inherit ConfigurationSection
Public NotInheritable Class AuthenticationSection
Inherits ConfigurationSection
- 繼承
範例
本節提供兩個程式代碼範例。 第一個示範如何針對 區段的 authentication
數個屬性以宣告方式指定值,這也可以當做 類別的成員 AuthenticationSection 來存取。 第二個示範如何使用 AuthenticationSection 類別。
下列組態檔範例示範如何以宣告方式 authentication
指定 區段的值。
注意
如果您使用 本節 credentials
,請務必遵循 ASP.NET 驗證中所述的指導方針。 為了達到延展性和更佳的安全性,建議使用外部資料庫來儲存用戶的認證。
<authentication mode="Forms">
<forms name="MyAppCookieName" loginUrl="login.aspx">
<credentials passwordFormat="SHA1">
<user name="Kim"
password="07B7F3EE06F278DB966BE960E7CBBD103DF30CA6"/>
<user name="John"
password="BA56E5E0366D003E98EA1C7F04ABF8FCB3753889"/>
</credentials>
</forms>
</authentication>
此範例使用SHA1。 由於 SHA1 的衝突問題,Microsoft 建議使用 SHA256。
下列程式代碼範例示範如何使用 AuthenticationSection 類別。
// Get the Web application configuration.
System.Configuration.Configuration configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(
"/aspnetTest");
// Get the section.
AuthenticationSection authenticationSection =
(AuthenticationSection)configuration.GetSection(
"system.web/authentication");
' Get the Web application configuration.
Dim configuration _
As System.Configuration.Configuration = _
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( _
"/aspnetTest")
' Get the section.
Dim authenticationSection _
As AuthenticationSection = _
CType(configuration.GetSection( _
"system.web/authentication"), AuthenticationSection)
備註
AuthenticationSection 類別 (Class) 提供以程式的方法,存取和修改組態檔的 authentication
區段。
注意
AuthenticationSection可以根據值為MachineToApplication的 section 屬性AllowDefinition所定義的限制,將資訊寫入組態檔的相關區段。 在階層中不允許的層級寫入組態檔的任何嘗試,都會產生剖析器所產生的錯誤訊息。 不過,您可以使用這個類別來讀取階層中任何層級的組態資訊。 為了安全與延展性,建議您使用外部存放庫,例如資料庫來保留用戶的認證。
建構函式
AuthenticationSection() |
初始化 AuthenticationSection 類別的新執行個體。 |
屬性
方法
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應