Introduction
In this article, we will be working on the registration page of the ASP.NET Core razor page web application. We will be adding more properties to the default registration page. We will be adding properties such as Name, Address, City and Postal code, as the default registration page contains only a few properties such as email, ID, password and confirm password.
Creating ASP.NET Core Razor Pages Web Application
Inside Visual Studio, we will create an ASP.NET Core Razor Pages web application.

We have to change the Authentication to Individual Users Accounts. This will make sure that identity is scaffolded, to make use of login and registration functionality inside the project.

The project folder should look like the following:

Now we will work on register functionality, in register functionality, we only have email and password fields but we will add more fields such as Name, Address, City, Phone number and Postal code.

In order to add those properties inside the database, we have to extend the IdentityUser that has already been implemented and we have to add additional properties there.
So, we need to add a new model class to create new properties. To add a model class, right-click on the models folder, add a new class and name it ApplicationUser.
- using Microsoft.AspNetCore.Identity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace SparkAutomation.Models
- {
- public class ApplicationUser : IdentityUser
- {
- public string Name { get; set; }
- public string Address { get; set; }
- public string City { get; set; }
- public string PostalCode { get; set; }
- }
- }
This ApplicationUser class is extending IdentityUser, that is it is an implementation of IdentityUser. Inside the ApplicationUser class, we are adding four properties such as Name, Address, City and Postal code.
Now we have to push these changes to the local database created earlier. So in order to push anything to the database, we need to make changes inside the ApplicationDbContext class created by default inside the Migration folder.
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore;
- using SparkAutomation.Models;
- namespace SparkAutomation.Data
- {
- public class ApplicationDbContext : IdentityDbContext
- {
- public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
- : base(options)
- {
- }
- public DbSet<ApplicationUser> ApplicationUser { get; set; }
- }
- }
Inside ApplicationDbContext class, we have to create a new DbSet for ApplicationUser.
Now we will add a migration, so we will go to tools, then NuGet Package Manager and click on Package Manager Console.
To add a migration, type the following command inside the Package Manager Console.
- add-migration AddPropertiesToUser
If we go through the newly created migration file, we can see that it is adding columns such as Name, Address, City and Postal code to AspNetUsers table.
- using Microsoft.EntityFrameworkCore.Migrations;
- namespace SparkAutomation.Data.Migrations
- {
- public partial class AddPropertiesToUser : Migration
- {
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AddColumn<string>(
- name: "Discriminator",
- table: "AspNetUsers",
- nullable: false,
- defaultValue: "");
- migrationBuilder.AddColumn<string>(
- name: "Address",
- table: "AspNetUsers",
- nullable: true);
- migrationBuilder.AddColumn<string>(
- name: "City",
- table: "AspNetUsers",
- nullable: true);
- migrationBuilder.AddColumn<string>(
- name: "Name",
- table: "AspNetUsers",
- nullable: true);
- migrationBuilder.AddColumn<string>(
- name: "PostalCode",
- table: "AspNetUsers",
- nullable: true);
- }
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropColumn(
- name: "Discriminator",
- table: "AspNetUsers");
- migrationBuilder.DropColumn(
- name: "Address",
- table: "AspNetUsers");
- migrationBuilder.DropColumn(
- name: "City",
- table: "AspNetUsers");
- migrationBuilder.DropColumn(
- name: "Name",
- table: "AspNetUsers");
- migrationBuilder.DropColumn(
- name: "PostalCode",
- table: "AspNetUsers");
- }
- }
- }
Now we need to update the database to make changes inside of it. To update the database, type following command inside the Package Manager Console.
- update-database
If we go back to the database, right-click on AspNetUsers table and click on view data. We can see all of the four new properties have been added inside the table.
After adding more properties inside the AspNetUsers table, we can add these properties inside the register page. In order to add more fields inside the registration page, we have to make changes inside the register razor page which has been auto-implemented by the identity.


pspPosted Jul 12, 2020, 2:05 PM
In case other reading this blog article should miss fields in db afterwards: Read Abhishek's follow-up article: https://www.c-sharpcorner.com/article/adding-roles-to-registration-razor-page-in-asp-net-core-razor-pages-web-applicat/
Inzi BhaiPosted Jun 4, 2020, 4:18 AM
Hi, I can see the new fields on the register form, but when i save it give me success message but additional fields are not saved in database, Where we need to map additional database fields so that it save them in database
Inzi BhaiPosted Jun 4, 2020, 2:23 AM
Hi, can you plz update code based on .net core 3.1 razor pages as when i created my project i couldnt see the files under folders such as Areas/Identity/IdentityHostingStartup.cs, also under Areas/Identity/Pages i only have one file _ViewStart.cshtml file. where can i find register page model and Register page as mentioned in article, can you please share more details and also upload complete code so that we also have some reference point to look at