Start a new project in ASP.NET Core 3, and how to customize the Identity User

When you want to create a new project in ASP.NET Core and you need to customize the Login, Register, Forgot Password Razor Page and etc. as you like. Also, you want to change the User table and some records. Thus, you will see more in the following how to customize the Identity User.

Create a Web Application Project:

Then select type of you project, API, MVC or Razor Page. I have chosen the Razor Page

Then click on Authentication -> Change. Select Individual User Accounts, and Store user accounts in-app then click OK

When the project completely loaded, please right click on Area folder, then Add and choose New Scaffolded Item as following:

Select Identity and click Add as following

In Identity window select Override all files and select the Data context class in step 2. It may have different name based on your project. Then click Add

If you have done the above steps well. You should see the following pages under the Area folder.

When you open your SQL Server an check the Database of this project and open the User Table you will see the following fields:

So, we want to customize the User table and add some fields. For doing this, please Right click on Data folder and add a new class called ApplicationUser.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

//****In my project the namespace is WebCore. It will be different in your project

namespace WebCore.Data 

{

    public class ApplicationUser

    {

    }

}

 

We need to add some records in the User table. In hence, the ApplicationUser has to inherit from the IdentityUser and then, add your properties of field. See below code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using Microsoft.AspNetCore.Identity;

//****In my project the namespace is WebCore. It will be different in your project

namespace WebCore.Data

{

    public class ApplicationUser:IdentityUser

    {

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public int Age { get; set; }

        public string Address { get; set; }

    }

}

 

Then in ApplicationDbContext.cs add <ApplicationUser> to the it's class:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>

    {

        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)

            : base(options)

        {

        }

    }