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 类提供一种以编程方式访问和修改配置文件的 authentication
节的方法。
注意
AuthenticationSection可以根据值为 MachineToApplication的 section 属性AllowDefinition定义的限制,将信息写入配置文件的相关节。 在层次结构中不允许的级别在配置文件中写入的任何尝试都将导致分析程序生成错误消息。 但是,可以使用此类在层次结构中的任何级别读取配置信息。 为了安全和可伸缩性,建议使用外部存储库(如数据库)来保留用户的凭据。
构造函数
AuthenticationSection() |
初始化 AuthenticationSection 类的新实例。 |
属性
方法
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈