Thursday, February 25, 2016

Create asp.net web app with default membership in database.

Create asp.net web app with default membership in database.

Steps:
1. Go to visual studio and create asp.net web application.
2. Add a webpage RegisterUser.aspx
3. In Toolbox --> drag "Login-->CreateUserWizard" tab to webpage.
4. In web.config file: Add membership and profiles like this

=>Connection string:
<connectionStrings>
    <add name="DefaultConnection" connectionString="MultipleActiveResultSets=True; Data Source=serverName;Initial Catalog=YourDB;Persist Security Info=True;User ID=username;Password=password;" providerName="System.Data.SqlClient"/>
</connectionStrings>

=>In <systerm.web> section add following lines in <membership> tag.

 <membership>
      <providers>
        <!--
        ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
        -->
        <clear />
        <remove name="AspNetSqlMembershipProvider" />
        <!--<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnection" applicationName="MISPortal"/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="DefaultConnection" applicationName="MISPortal"/>-->
        <add connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="MyProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="DefaultConnection" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
      </providers>
    </membership>
 <profile>
      <providers>
        <!--
        ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
        -->
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="DefaultConnection" applicationName="RMS" />
      </providers>
    </profile>
    <roleManager enabled="true">
      <providers>
        <clear />
        <remove name="AspNetSqlRoleProvider" />
        <add connectionStringName="DefaultConnection" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <remove name="AspNetWindowsTokenRoleProvider" />
        <!--<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" applicationName="MISPortal"/>-->
      </providers>

    </roleManager>

5. Create blankDatabase in SqlServer 2008 or sqlServer 2012
6. Go to visualstudio command prompt and type command aspnet_regsql
7. follow the instruction to add database for creating membership tables in sqlServer database which you have selected through aspnet_regSql command.
  Default membership tables will created automatically in database.
8. Now run your website RegisterUserpage
9. Enter required details of user and click on "Create User" button.
    User will register according to user membership tables.
========================================================================
Similarly add login wizard for user Login and run application.
Login wizard will automatically work for membership.




No comments:

Post a Comment