What are the steps to enable Forms Authentication in ASP.NET MVC (Model View Controller)?
1. Create a Controller called LoginController, an Action Method called Login follows.
2. Right click the Login action and create a view called Login which contain,
a. Input controls for accepting user credentials
b. A submit button
c. Both of the above should be encapsulated inside a form tag with method set as “POST”
and action set to one of the action method.
<!—add input controls and a
submit button -->
3. Open web.config file located in the global level not inside views folder.
4. In system.web section add a new tag called authentication and set mode to “Forms”.
5. Inside authentication add a section called Forms and set LoginUrl to action method created in step 1.
6. Add Authorize attribute at action/controller/global level make sure that requests are authorized.
static void RegisterGlobalFilters(GlobalFilterCollection filters)
In case authorize attribute is added at global level make sure attach AllowAnonymous attribute to Login and Logic actions in LoginController otherwise without login accessing them will not be possible and hence leads to dead lock and error.
7. Create a cookie inside LoginCheck action as follows and redirect to appropriate action.
//Check username and Password
For technical trainings on various topics like WCF (Windows Communication
Foundation), MVC (Model View Controller), Business Intelligence, Design
Patterns, WPF, TFS and Basic fundamentals feel free to contact
For more stuff like this, click
. Subscribe to
or follow at twitter
See the following video on Forms Authentication in ASP.NET MVC (Model View