How to setup Membership and Role Provider in web.config

Often I would create a new project and need to tie up the application in aspnet database. And yet I often forgot how to setup the connection string. So I'm logging them here:

Find the end of the system.web tag: </system.web>
<membership defaultProvider="SQLMembershipProvider">
        <add connectionStringName="aspnetdb" applicationName="applicationName" enablePasswordRetrieval="True" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordFormat="Clear" name="SQLMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>
    <roleManager enabled="true" defaultProvider="SqlRoleManager">
        <add connectionStringName="aspnetdb" applicationName="applicationName" name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider"/>
Also you need to define the connection string in <connectionStrings>.

<add name="aspnetdb" connectionString="Data Source=Server;Initial Catalog=Database;Persist Security Info=True;User ID=usr;Password=pwd;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>

Note: applicationName, is the entry in the aspnet_Applications table.

I guess you can figure out what the other parameter means.
How to setup Membership and Role Provider in web.config How to setup Membership and Role Provider in web.config Reviewed by Edward Legaspi on Tuesday, January 04, 2011 Rating: 5

No comments:

Powered by Blogger.