Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

CHAPTER 7: Security and Membership > Providing a Login Page

Providing a Login Page

Once a user has registered with the site, they need to be able to log in on their next visit. We will achieve this by providing them with a login page, which can be accessed via the Login link displayed by the AccountSummary helper for non-authenticated users.

Add a new file to the root of the site, called login.cshtml. When login.cshtml is loaded for the first time, a simple login form will be displayed containing two textboxes, one for the username and another for the password, and a “Remember me on this computer” checkbox.

When the form is submitted, we will carry out some basic validation to ensure that the textboxes are not empty. If the validation is passed, we will attempt to log the user in using the WebSecurity.Login() method. If the user has checked the rememberMe checkbox, the Login() method will set the authentication token in the cookie to be persisted beyond the current session. That way, when they return to the site at a later date, they will be automatically logged in as the authentication token in the cookie will still be valid.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint