Membership Provider

Embed Size (px)

Citation preview

  • 8/4/2019 Membership Provider

    1/9

  • 8/4/2019 Membership Provider

    2/9

    Contents Configure forms authentication

    Install the membership database

    Configure the SqlMembershipProvider

    Configure the SqlRoleProvider

    Create users

    Authenticate users

    Demonstration

  • 8/4/2019 Membership Provider

    3/9

    Configure forms authentication Section 1

    Section 2

  • 8/4/2019 Membership Provider

    4/9

    Install the membership database Execute Command

    aspnet_regsql.exe -E -S server -d dbname -A mr

  • 8/4/2019 Membership Provider

    5/9

    Configure the

    SqlMembershipProviderWeb.Config

  • 8/4/2019 Membership Provider

    6/9

    Configure the SqlRoleProviderWeb.Config

  • 8/4/2019 Membership Provider

    7/9

    Create users Use the Web Site Administration Tool, which provides a wizard-like interface for creating new users. To start this tool, click

    ASP.NET Configuration on theWebsite menu in Visual Studio2005.

    Create an ASP.NET page that contains a CreateUserWizardcontrol. This control uses the configured membership providerto encapsulate the logic of creating a new user.

    Create an ASP.NET Web page that contains the TextBox controlsused to collect the user name and password (and, optionally, theuser's e-mail address), and then use theMembership.CreateUserAPI to create a new user in themembership system.

    The following code shows how to call MembershipCreateUser.Membership.CreateUser("Username", "P@ssw0rd", "userName@emailAddress");

  • 8/4/2019 Membership Provider

    8/9

    Authenticate usersTo authenticate users, you must provide a login form. This could be aseparate page or a special area on your application's home page.

    You can create the login form in the following ways:

    Use the ASP.NET 2.0 login controls. The ASP.NET login controlsencapsulate nearly all of the logic required to obtain credentials fromusers and to validate them against a user store. They use the configuredmembership provider. You do not need to write any additional code.

    After the user is validated, the login controls automatically saveinformation about the user; for example, by using an encrypted cookie

    if the user's browser accepts cookies. Create a custom login form by using ASP.NET TextBox controls. If you

    create a custom login form with simple TextBox controls, you canprompt the user for a user name and password, and then call theValidateUser method of the Membership class to perform thevalidation.

  • 8/4/2019 Membership Provider

    9/9

    Demonstration