FormsAuthenticationConfiguration 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
配置 ASP.NET 应用程序以使用 AuthenticationMode 窗体模式。
public ref class FormsAuthenticationConfiguration sealed : System::Configuration::ConfigurationElement
public sealed class FormsAuthenticationConfiguration : System.Configuration.ConfigurationElement
type FormsAuthenticationConfiguration = class
inherit ConfigurationElement
Public NotInheritable Class FormsAuthenticationConfiguration
Inherits ConfigurationElement
- 继承
示例
下面的代码示例演示如何从现有 Web 应用程序的配置文件中获取 FormsAuthenticationConfiguration 对象。 可以使用此对象访问其成员。 配置文件将包含类似于以下内容的设置。
注意 如果使用本 credentials
部分,请务必遵循 ASP.NET 身份验证中介绍的准则。 为了提高可伸缩性和更好的安全性,建议使用外部数据库来存储用户的凭据。 有关生成安全 ASP.NET 应用程序的详细信息,请参阅保护 ASP.NET 应用程序和构建安全 ASP.NET 应用程序:身份验证、授权和安全通信。
此示例使用 SHA1。 由于与 SHA1 冲突,Microsoft 建议使用 SHA256。
<authentication mode="Forms">
<forms name="MyAppCookie" loginUrl="login.aspx"
defaultUrl="default.aspx"
protection="Encryption" timeout="5" path="aspnetTest"
slidingExpiration="false"
cookieless="UseCookies" domain="domainName">
<credentials passwordFormat="SHA1">
<user name="aspnetuser1"
password="5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8"/>
<user name="aspnetuser2"
password="E38AD214943DAAD1D64C102FAEC29DE4AFE9DA3D"/>
</credentials>
</forms>
</authentication>
// Get the Web application configuration.
System.Configuration.Configuration configuration =
WebConfigurationManager.OpenWebConfiguration("/aspnetTest");
// Get the external Authentication section.
AuthenticationSection authenticationSection =
(AuthenticationSection)configuration.GetSection(
"system.web/authentication");
// Get the external Forms section .
FormsAuthenticationConfiguration formsAuthentication =
authenticationSection.Forms;
' Get the Web application configuration.
Dim configuration As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
"/aspnetTest")
' Get the external Authentication section.
Dim authenticationSection _
As AuthenticationSection = _
CType(configuration.GetSection( _
"system.web/authentication"), AuthenticationSection)
' Get the external Forms section .
Dim formsAuthentication _
As FormsAuthenticationConfiguration = _
authenticationSection.Forms
注解
该 FormsAuthenticationConfiguration 类提供了一种以编程方式访问和修改 forms
配置 authentication
节元素的方法。
此类型是包含 FormsAuthenticationCredentials类型、类型和 FormsAuthenticationUserCollection类型的 FormsAuthenticationUser 组的一部分。 集合类型以外的类型直接影响基础配置标记。
备注
可以根据其值为MachineToApplication的 section 属性AllowDefinition定义的限制,将FormsAuthenticationConfiguration信息写入配置文件的相关部分。 在层次结构中不允许的某个级别的配置文件中写入的任何尝试都将导致分析程序生成的错误消息。 但是,可以使用此类在层次结构中的任何级别读取配置信息。 为了获得安全性和可伸缩性,建议使用外部存储库(如数据库)保留用户的凭据。
构造函数
FormsAuthenticationConfiguration() |
初始化 FormsAuthenticationConfiguration 类的新实例。 |