
Create a Web Site with Membership and User Login
Before you work with ASP.NET membership and roles, you must have an available Web site, and then you need to configure that Web site to enable membership and set up roles. If you have already completed Walkthrough: Creating a Web Site with Membership and User Login (Visual Studio), you can use the Web site that you configured in that walkthrough.
Creating a Web Site
If you already have created a Web site in Visual Web Developer, (for example, Walkthrough: Creating a Basic Web Page in Visual Web Developer), you can use that Web site and skip to the next section. Otherwise, create a new Web site and page by following these steps.
To create a local IIS Web site
-
Open Visual Web Developer.
-
On the File menu, click New Web Site.
The New Web Site dialog box appears.
-
Under Visual Studio installed templates, click ASP.NET Web Site.
-
In the Language drop-down list, click the programming language in which you prefer to work.
-
In the Location drop-down list, select HTTP.
Alternatively, you can select File System if you do not have an IIS server available. However, using HTTP mimics a real-world deployment scenario, and allows you to test your pages by viewing them in a browser.
-
Click Browse.
The Choose Location dialog box appears. If you selected HTTP in the previous step, the Local IIS button should be selected. If not, click Local IIS.
-
Select the Default Web Site node.
-
Click the Create New Web Application icon (in the top right corner), and then name the new Web site SiteNavigation.
-
Click Open, and then Click OK.
Visual Web Developer creates the Web site and opens a new page named Default.aspx. By default, Visual Web Developer creates new pages with a matching code-behind file — Default.aspx.cs, in this case. You can change this when you create subsequent new pages using the Add New Item wizard.
Note |
|---|
| Sometimes, if a previous version of the .NET Framework was installed before Visual Web Developer, you might get an error about configuring the Web site to use the latest version of the .NET Framework. You can correct this by clicking Yes on the dialog box that appears, to enable ASP.NET version 2.0 on your server, or by using IIS Manager. In IIS Manager, right-click your application, click Properties, and then click the ASP.NET tab. Beside ASP.NET Version, select the version of the .NET Framework that was installed with Visual Web Developer. |
Enabling Membership and Creating a User
If you do not already have membership enabled, use the following procedure to enable it. Otherwise, go to the next section.
To enable membership
-
In Visual Web Developer, on the Web site menu, click ASP.NET Configuration.
The Web Site Administration Tool appears.
-
Click the Security tab, under Users, click Select authentication type, click From the Internet, and then click Done.
This option specifies that your application will use Forms authentication, where users will log in to the application by using a login page that you will create later in this walkthrough.
-
On the Security tab, click Create User.
You are going to create two user accounts for your application.
-
In the Create User box, type information that defines a user of your application. Use the following values as guidelines. You can use any values that you like, but be sure to note your entries for use later in this walkthrough.
-
User Name Use the name, Customer01, which is the name of our first user account.
-
Password Use a password of your choice, preferably a strong password, which is a password that contains a minimum of eight characters, and includes uppercase and lowercase letters as well as punctuation.
-
E-mail Use a properly formatted e-mail address. Alternatively, you can use a non-existent e-mail address because this walkthrough does not include sending e-mail.
-
Security Question and Security Answer Type a question and answer that can be used later, if you need to recover your password.
-
Select the Active User check box, and then click Create User.
-
On the confirmation page, click Continue.
-
Repeat the preceding three steps to create one more user account named Employee01. (When you create roles for these user accounts, you will use names with all lowercase letters.)
-
Click the Back button at the bottom right corner of the page to return to the Security start page.
Creating a User Login Page
To test the membership and role settings that you will configure later in this walkthrough, you need to create a way for users to log in so that you can identify them.
To create a default page for all users that displays login status
-
Open the Default.aspx page, and then switch to Design view.
If you do not have a Default.aspx page, add one to the root of your Web site.
Note |
|---|
| Be sure to name the page Default.aspx; this name is used later in this walkthrough. |
-
In the Toolbox, from the Login group, drag a LoginStatus control onto the page.
The LoginStatus control automatically takes users to the Login.aspx page, if they have not already logged in.
-
Place the cursor to the right of the LoginStatus control, press ENTER, and then type the following, including the extra space: Hello .
-
In the Toolbox, from the Login group, drag a LoginName control onto the page.
The LoginName control will display the user's name, if the user is logged in.
-
Save the page, and then close it.
You now have a home page that is available to all users. The next step is to create a simple login page.
To create a login page
-
Add a page named Login.aspx to the root of your Web site.
-
Open the Login.aspx page, and then switch to Design view.
-
In the Toolbox, from the Login group, drag a Login control onto the page.
-
Right-click the Login control, click Properties, and then set DestinationPageUrl to Default.aspx.
-
Save the page, and then close it.