Introduction

This article shows Form Authentication in ASP.NET MVC applications. There are many web applications that restrict access to specific resources; those resources are only accessible by the authenticated users. Form Authentication authenticates the user for accessing the resources when the user is logged onto the site.

We create a web application project template for the ASP.NET MVC application that provides the controller, model class and views for adding the ASP.NET Form Authentication to the application. There are many functions, they are Logon, Logoff and Change Password.

Now create the MVC application..

Step 1

Open Visual Studio 2010 then use the following procedure:

After creating this project the Solution Explorer looks like this:

225.jpg

The Controllers folder has the "AccountController" that contains the "Action" method that can register the new user login and logout of the user of the application. We can change the password of the existing user. the the "view folder" contains the "Account folder" that has the views for supporting these actions. The "Model Folder" contains the "AccountModels.cs " class, this class defines the data objects, services and validation that supports Form Authentication.

Step 2

Now we register the user.

Step 3

For changing the password, we apply some changes to the application.

Step 4

After performing the three steps above, we can specify the part of the application to be restricted by the authentication of the user. We can do that using the [Authorized] attribute.