ASP.NET MVC 5 + ASP.NET Identity Framework 2.0 – Customized User Account Registration Attribute ( Registration )

ASP.NET MVC 5 + ASP.NET Identity Framework 2.0 – Customized User Account Registration Attribute ( Registration )
 
1. Execute the Following SQL Statement to Add the Extend Attribute Field on the SQL Server Database ( AspNetUsers ) Table.

 
   ALTER TABLE [dbo].[AspNetUsers] ADD [PostTitle] nvarchar(150) NOT NULL DEFAULT('')
 

2. Update the Registration Form View Model from File "\Models\AccountViewModels.cs".

 
   public class RegisterViewModel
   {
      … …
 
      [Display(Name = "PostTitle")]
      public string PostTitle { get; set; }
   }
 

3. Update the Registration Form View from File "\Views\Account\Register.cshtml".
 
4. Update the ApplicationUser Class Property from the File "\Models\IdentityModels.cs".

 
   public class ApplicationUser : IdentityUser
   {
      public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
      {
         var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
         return userIdentity;
      }
 
      public string PostTitle { get; set; }
   }
 

5. Update the "AccountController" Controller – "Register" Form Post Method from the File "\Controllers\AccountController.cs".

 
   [HttpPost]
   [AllowAnonymous]
   [ValidateAntiForgeryToken]
   public async Task<ActionResult> Register(RegisterViewModel model)
   {
      if (ModelState.IsValid)
      {
         var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
 
         user.PostTitle = model.PostTitle;
 
         var result = await UserManager.CreateAsync(user, model.Password);
 
         if (result.Succeeded)
         {
            await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
            return RedirectToAction("Index", "Home");
         }
 
         AddErrors(result);
      }
 
      return View(model);
   }
 

6. Finally, the New Field Value from Account Registration Form would be added on the ASP.NET Identity 2.0 Database Table.
    There is No Code which needs to be overrided on the Encapsulation Class. Great.

Reference From : ASP.NET Identity 2.0: Customizing Users and Roles