Walkthrough: Creating a Web Site with Membership and User Login A common requirement for Web sites is to allow only some members or other authenticated users to see certain pages. In that case, the application must prompt the user for a name and password. The application must also include a way to hide information from anonymous users (users who are not logged in). This walkthrough shows you how to use ASP.NET controls and ASP.NET membership services to create an application that performs all these tasks. For more information, see Introduction to Membership[->0]. Tasks illustrated in this walkthrough include:
· Configuring an application to include ASP.NET membership services, and how to define users. · Using login controls to get user credentials and to display information to logged-in users. · Protecting one or more pages in your application so that only logged-in users can view them. · Allowing new users to register at your site.
· Allowing members to change and reset their passwords.
In order to complete this walkthrough, you will need:
· Microsoft Visual Web Developer.
· Microsoft Internet Information Services (IIS) installed locally on your computer. · SQL Server Express Edition installed locally on your computer. · Access to an e-mail server that can forward e-mail messages. (The server does not have to be able to receive messages.) IIS includes the Default SMTP virtual server, a mail server that is suitable for this walkthrough. For more information about configuring this server. If you are working on a local area network, check with your network administrator for information about access to an e-mail server. Creating the Web Site[->2]
If you have already created a Web site in Microsoft Visual Studio (for example, by working with the topic Walkthrough: Creating a Basic Web Page in Visual Web Developer[->3] ), you can use that Web site and skip to "Configuring Membership" later in this walkthrough. Otherwise, create a new Web site and page by following these steps. To create a local IIS Web site
1. Open Visual Studio.
2. On the File menu, click NewWeb Site.
The New Web Site dialog box appears.
3. Under Visual Studio installed templates, select ASP.NET Web Site. 4. In the Location list box, select HTTP. Click Browse.
The Choose Location dialog box appears.
5. Select Local IIS.
6. Open Local Web Servers.
7. Select Default Web Site.
8. Click the Create New Web Application icon () above the list of Web sites and then name the new Web site membership. 9. Click Open.
The Choose Location dialog box closes.
10. In the Languages box, click the programming language you prefer to work in. The programming language you choose will be the default for your Web site, but you can set the programming languages for each page individually. 11. Click OK in the New Web Site dialog box.
Visual Web Developer creates the Web site and a new page named Default.aspx. Configuring Membership[->4]
Later in this walkthrough you will put pages into a subdirectory that is protected. You must create the subdirectory now so that you can configure security for it later in the walkthrough. To add a new folder to the Web site
1. In Solution Explorer, right-click the name of your Web site and click New Folder. 2. Name the folder MemberPages.
Before you work with ASP.NET membership, you must configure your application to enable membership and to set up users. You can use the Web Site Administration tool, which provides a wizard-like interface for making configuration settings. When you complete the Setup Wizard, a SQL Server database named ASPNETDB.MDF is created in the App_Data folder of the project. For more information. For this walkthrough, you will define a single user.
To create a membership user
1. On the Website menu, click ASP.NET Configuration.
2. Select the Security tab, click the link to Use the security Setup Wizard to configure security step by step, and then click Next. 3. Proceed to Step 2 of the wizard and select the From the Internet option. The wizard displays a page where you can select the authentication method that your Web site will use. This option specifies that your application will use Forms authentication, where users will log in to the application using a login pag...