How to create a login page using ASP.NET MVC 3 Razor (1 of 5)

Опубликовано: 12 Май 2026
на канале: jalbao
153,162
251

Simple example of how to create an MVC 3 Razor web application that forces a users to login in order to access secure parts of the website.

Outline:
1. In Visual Studio 2010, create an empty ASP.NET MVC 3 Razor application
2. Create a Home Controller
3. Create a Model for the Login data using Data Annotations
4. Create a Login Controller
5. Create an method decorated with the HttpPost attribute
6. Create a View for the Login HTML Form
7. Use Razor @Html helpers to build the HTML Form
8. Discuss Client-side and Server-side validation
9. Update Web.Config file to allow and disallow anonymous users
10. Update Web.Config to force users to the Login View
11. Create a Layout (Master) page for anonymous users and a different Layout for authenticated users