Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • ASP.Net membership provider Implementation:

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 413
    Comment on it

    ASP.Net membership provider Implementation:

    Before we start with, let us have a brief introduction about Asp.Net Membership:

    Introduction:

    ASP.NET membership provides an implicit way to validate and store user credentials and helps

    to manage user authentication throughout the application.It also helps in Creating new users

    and passwords,Storing membership information,Authenticating users who visit the

    application,Creating,Changing and Resetting of Password,etc.

    Implementing ASP.Net membership provider:

    To implement a membership provider, we create a class that inherits the MembershipProvider abstract class from the System.Web.Security namespace. We can enable ASP.NET Membership for an application by directly editing the Web.config file for that application, or we can use the Web Site Administration Tool, which provides a wizard-based interface. While implementing we have to specify the following points:

    1.Which membership provider to use.
    2.Password options such as encryption and whether to support password recovery based on a user-specific question.
    3.Users and passwords.

    To configure the membership provider:

    Write the following code in the Web.config file.

    <!-- Configure the Sql Membership Provider -->
    <membership defaultProvider="SqlMembershipProvider" userIsOnlineTimeWindow="15">
      <providers>
        <clear />
          <add 
            name="SqlMembershipProvider" 
            type="System.Web.Security.SqlMembershipProvider" 
            connectionStringName="SqlConn"
            applicationName="MembershipAndRoleProviderSample"
            enablePasswordRetrieval="false"
            enablePasswordReset="false"
            requiresQuestionAndAnswer="false"
            requiresUniqueEmail="true"
            passwordFormat="Hashed" />
      </providers>
    </membership>
    

    To configure service security to accept the user name/password combination:

    Write the following code in the Web.config file.

    <system.serviceModel>
    <bindings>
      <wsHttpBinding>
      <!-- Set up a binding that uses UserName as the client credential type -->
        <binding name="MembershipBinding">
          <security mode ="Message">
            <message clientCredentialType ="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    </system.serviceModel>
    

    To configure a service to use the membership provider:

    Write the following code in the Web.config file.

    <behaviors>
       <serviceBehaviors>
          <behavior name="MyServiceBehavior">
             <serviceCredentials>
                <userNameAuthentication 
                userNamePasswordValidationMode="MembershipProvider"
                membershipProviderName="SqlMembershipProvider" />
             </serviceCredentials>
          </behavior>
       </serviceBehaviors>
    </behaviors>
    

    After we are done with the web.config file, we will create a database in sql and then open the visual studio command prompt & run the following command:

    aspnet_regsql

    This will open the wizard in which we can select the database created above either on local machine or on server, now this database will contain all the membership tables. Now by going to the register.aspx page in the application we can create the users or can create our own page or control for creating users.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: