Seed the database with initial Users in MVC 5

 

Read full article on Falafel blog

In MVC 5 applications you may want to seed the database with initial users for various reasons. You may want default users and roles added as part of the application. In this post, we will take a look at how to  seed the database with default users.
The MVC 5 application uses ASP.Net Identity 2.0 to manage users, roles and identities. ASP.Net Identity 2.0 uses the Entity framework code first approach to create a database. To seed the database, first you need to enable migration on the database. To enable migration, in the package manager console run the command enable-migrations as shown below:

After successfully enabling migration you should find a Migrations folder in the solution explorer.

 

Read full article on Falafel blog

Custom Action Filter in ASP.NET MVC 5

Read full article on Falafel blog here

ASP.NET MVC 5 provides five different kinds of Filters. They are as follows:

  1. Authentication [Introduced in MVC5]
  2. Authorization
  3. Action
  4. Result
  5. Exception

Filters are used to inject logic at the different levels of request processing. Let us understand where at the various stages of request processing different filters get applied.

  • Authentication filter runs before any other filter or action method
  • Authorization filter runs after Authentication filter and before any other filter or action method
  • Action filter runs before and after any action method
  • Result filter runs before and after execution of any action result
  • Exception filter runs only if action methods, filters or action results throw an exception

Read full article on Falafel blog here