Introduction: ASP.NET Identity is the new membership
system for ASP.NET applications. In
the existing ASP.net, the information about user and profile are stored in
separate tables. The profile information about the user was handled by profile
provider. This makes it hard to customize profile data and associate it with
user and application data. ASP.net makes it easy to add profile data for user.
Steps:
Create a new ASP.Net Application with MVC Template : Open Visual
Studio 2013 |New Project|ASP.Net Web Application |select MVC.
Run the existing Register Page: It takes
username and password. We’ll add new fields such as ‘First Name’, ’Last name’, ’Email’,
’Language’, and ‘Country to store these additional information when a user registers.
Enable Entity Framework Code First Database
Migration: Open Package Manager Console and run the command- "Enable-Migrations".
Add new properties to Model: In the
solution explorer, open “Models” folder and then open “IdentiModels.cs” file.
We’ll add the new fields as properties.
Add New Migration and update Database - execute the
following commands in “Package Manager Console”. Use these two commands : Add-Migration "nameofyourprofile" and Update-Database.
Check the ASPNetUsers table and verify the new fields:
Update Model: Open
RegisterViewModel from Models| AccountViewModels| RegisterViewModel in the solution explorer.
The "Models" folder should like this:
Update View: Open Register.cshtml
from Views |Account |Register.cshtml
Update Controller: Open Register from Controller |AccountController
| Register
Run the project : Build and Run the project.
After registering the user, you should see the user's information in the table. Browse as View |Server Explorer |Tables |ASPNetUsers. Right click on "ASPNetUsers" table and select "show table data".