Chapter 27B. Create a Login Page in MVC

By default, applications that use the ASP.NET MVC framework use Forms authentication. If your application uses Forms authentication to authenticate users, you must create a login page. In this lesson I show you how to both add users and how to authenticate those users by using the AccountController that is included as part of the ASP.NET MVC Web Application template.

As you have seen, the easiest way to add new users is to use the ASP.NET Web Site Administration Tool (WSAT) that was demonstrated in Lesson 26. However, unless your web site has only a few users, you will want to add a page to your site to allow new users either to register themselves or be registered by an administrator.

When you create a new project using the ASP.NET MVC Web Application template it includes an AccountController plus its associated models and views. It also defines two services:

  • AccountMembershipService

  • FormsAuthenticationService

The AccountMembershipService uses the Membership provider to store and validate usernames and passwords. For more information on the Membership provider, see Lesson 26. The FormsAuthenticationService uses the Forms Authentication system. It too was covered in Lesson 26. Figure 27B-1 shows the files that are included in the Solution Explorer.

FIGURE 27B-1

Figure 27B.1. FIGURE 27B-1

REGISTRATION PAGE

This is the model that is used for the Registration page: ...

Get ASP.NET 4 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.