ASP.NET Membership is configured using the
-
Which membership provider (or providers) to use. (This typically also specifies what database to store membership information in.)
-
Password options such as encryption and whether to support password recovery based on a user-specific question.
-
Users and passwords. If you are using the Web Site Administration Tool, you can create and manage users directly. Otherwise, you must call membership functions to create and manage users programmatically.
For an example of configuring ASP.NET Membership using the Web Site Administration Tool, see
Specifying the Default Provider
You specify the default membership provider using the defaultProvider attribute of the membership element. The machine configuration specifies a
Note |
---|
You need to set up the database used by the SqlMembershipProvider before using it in an application. For details, see |
You can also specify the default provider instance and options for that provider by configuring a provider in the membership section. You use the providers element to identify a provider to add to the collection of providers available for the application. You can identify your provider instance as the default provider by using the value of the name attribute as the defaultProvider value. When you specify a provider instance, you must also specify a valid connection string for that instance by using the
В | Copy Code |
---|---|
<configuration> <connectionStrings> <add name="MySqlConnection" connectionString="Data Source=MySqlServer;Initial Catalog=aspnetdb;Integrated Security=SSPI;" /> </connectionStrings> <system.web> <authentication mode="Forms" > <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" /> </authentication> <authorization> <deny users="?" /> </authorization> <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" applicationName="MyApplication" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" /> </providers> </membership> </system.web> </configuration> |