O'Reilly logo

ASP.NET 4 24-Hour Trainer by Toi B. Wright

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required