Configure your website to use Membership provider feature.



***   Configure your website to use Membership provider (aspnet_membership) feature ***.

Asp.net provides facility for inbuilt membership management and roles management.  You find many article on it on google I am not going on details about t. but here I am discuss how to apply membership in out asp.net web application or web site

First you need to run below script. Download it and run in your database.


Namespace: -    System.Web.Security  you have to include this namespace to use all method of aspnet membership provider.
Second you need to change your web.config section. Add below section in your web.config section.

(This will make your website Form Authentication Mode and Apply all setting which aspnetmembership required.)

<authentication mode="Forms">
                  <forms name="login" loginUrl="Login.aspx" defaultUrl="Default.aspx" protection="All" cookieless="UseCookies" path="/" timeout="600000">
                  forms>
            authentication>


            <authorization>
                  <deny users="?"/>
                 
            authorization>
            <membership defaultProvider="SqlMembershipProvider" userIsOnlineTimeWindow="15">
                  <providers>
                        <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="defaultConnection" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="HelpdeskApplication" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="5" passwordFormat="Clear" minRequiredNonalphanumericCharacters="0"/>
                  providers>
            membership>
            <roleManager enabled="true" cacheRolesInCookie="true" defaultProvider="SqlRoleProvider" cookieName=".ASPXROLES" cookiePath="/" cookieTimeout="30" cookieRequireSSL="false" cookieSlidingExpiration="true" createPersistentCookie="false" cookieProtection="All">
                  <providers>
                        <add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="defaultConnection" applicationName="HelpdeskApplication"/>
                  providers>
                  roleManager>


Now you can use all Feature of memmbership Provier. Below are some basic methods which are used.
1.  CreateUser  :- Createuser method used to create a new user.

Membership.CreateUser Method (String, String)

MembershipUser user = Membership.CreateUser(UserId, password, email);

You not nees to write any other code. It’s manage by .net frame work.


2.       MembershipUser user = Membership.GetUser(“userid”);
This method used to get all created member information.

3.       Membership.DeleteUser(UserId, true);
This method used to delete specific userid from a database. Second argument used to delete all related records or not.

4.       RoleProvider.CreateRole
This method is used to create a new role.

5.  Roles.AddUserToRole

This method is used to assign role to user.
Roles.AddUserToRole("username", "roles");

6.  Roles.AddUsersToRole
 
This method used to assign several user to one role.
      Roles.AddUsersToRole(
      new string[] { "username1", "username2" }, "Roles");
 
 
7.       MembershipProvider.ChangePassword
This method is used to update password for user.



Enjoy !!!!  if you have any query then  let me know......

Posted in | 0 comments