Compartir a través de


How to: Create an ASP.NET Login Page

You can create a login page by using the ASP.NET Login control. The control consists of text boxes, a check box and a button control. The text boxes collect username and password information from the user. The check box is used to remember the user's credentials and the button is used to submit the information the user provides. The login control simplifies creating login pages for form authentication. This login control takes a user name and password and uses ASP.NET membership and forms authentication to verify the user's credentials and create an authentication ticket. For information about how to configure ASP.NET membership and forms authentication, see Introduction to Membership. If a user selects the Remember me next time check box, the control creates a persistent cookie that remembers the user's credentials.

The login control functions as expected when you create an ASP.NET Web site with membership, configure membership, and create a membership user. For information about how to create a Web site with membership, see Walkthrough: Creating a Web Site with Membership and User Login.

To create a login page

  1. Create an ASP.NET Web application that uses ASP.NET membership. For more information and examples, see Walkthrough: Creating a Web Site with Membership and User Login. For information about how to configure membership, see Configuring an ASP.NET Application to Use Membership.

  2. Create an ASP.NET Web page named Login.aspx in your application.

    Note

    By default, ASP.NET forms authentication is configured to use a page named Login.aspx. You can change the default login page name in the Web.config file for your application using the LoginUrl property.

  3. Add a Login control to the page.

  4. Set the control's DestinationPageUrl property to the name of the page that the user will be redirected to after they log in. For example, you can set the DestinationPageUrl property to DestinationPageUrl="~/Membership/MembersHome.aspx", a members only page. If you do not specify a value for the DestinationPageUrl property, the user will be redirected to the original page the user requested after successfully logging in.

    The following example shows the markup for a Login control:

    <asp:Login 
      ID="Login1" 
      runat="server" 
      DestinationPageUrl="~/MembersHome.aspx">
    </asp:Login>
    

You can set additional properties to customize the display for logged-in users. For more information, see Walkthrough: Creating a Web Site with Membership and User Login.

See Also

Reference

ASP.NET Login Controls Overview

Other Resources

Managing Users by Using Membership