Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

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">
      <providers>
        <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"/>
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="SqlRoleManager">
      <providers>
        <add connectionStringName="aspnetdb" applicationName="applicationName" name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider"/>
      </providers>
    </roleManager>
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.