Lab 3 - Modify Identity DB on ASP.NET Core
Lab 3 - Modify Identity DB on ASP.NET Core
NET Core
In this topic, you learn how to add custom user data to the Identity DB. You can also learn how to modify
the user registration page and user profile page for your own use.
[PersonalData]
public string ? CustomerFullName { get; set; }
[PersonalData]
public int CustomerAge { get; set; }
[PersonalData]
public string ? CustomerAddress { get; set; }
[PersonalData]
public DateTime CustomerDOB { get; set; }
4. To modify the current Identity database, you must use the Package Manager Console
(PMC).
5. To start the PMC, click on the Tools > NuGet Package Manager > Package Manager
Console.
6. In the Visual Studio Package Manager Console, type the below commands:
Add-Migration CustomUserData
A migration code will be generated after the add-migration command. This migration code
will modify the existing structural schema of the tables to the latest schema.
7. After creating a migration file using the add-migration command, you must update the
database. Execute the Update-Database command to create or modify a database schema.
Update-Database
8. Now, in Visual Studio, open the SQL Server Object Explorer (SSOX).
9. You will see your database “MVC_APU_FlowerShop2023” located in the SQL Server and
all the default tables are under the database. Now, open the dbo.AspNetUsers, you will see
the new columns appear in the table.
[Required]
[Display(Name = "Customer DOB")]
[DataType(DataType.Date)]
public DateTime DoB { get; set; }
user.CustomerFullName = Input.customerfullname;
user.CustomerDOB = Input.DoB;
user.EmailConfirmed = true;
[Required(ErrorMessage = "You must enter the name first before submitting your
form!")]
[StringLength(256, ErrorMessage = "You must enter the value between 6 - 256
chars", MinimumLength = 6)]
[Display(Name = "Your Full Name")] //label
public string customerfullname { get; set; }
[Required]
[Display(Name = "Your DOB")]
[DataType(DataType.Date)]
public DateTime DoB { get; set; }
[Required(ErrorMessage = "You must enter the age first before submitting your
form!")]
[Range(18, 100, ErrorMessage ="You must be 18 years old when register this
member!")]
[Display(Name = "Your Age")] //label
public int age { get; set; }
[Required]
[DataType(DataType.MultilineText)]
[Display(Name = "Your Address")]
public string Address { get; set; }
if(Input.customerfullname != user.CustomerFullName)
{
user.CustomerFullName = Input.customerfullname;
}
if (Input.DoB != user.CustomerDOB)
{
user.CustomerDOB = Input.DoB;
}
if (Input.Address != user.CustomerAddress)
{
user.CustomerAddress = Input.Address;
}
if (Input.age != user.CustomerAge)
{
user.CustomerAge = Input.age;
}
await _userManager.UpdateAsync(user);
1. Once every above step is done, let’s test the application now.
Summary:
In this tutorial, we learned how to build add, download, and delete custom user data to Identity DB
in an ASP.NET Core project. In the next tutorial, we will learn how to create a simple CRUD
operation in an ASP.NET Core project.