Extending the ApplicationUser

The next thing to do is to empower our ApplicationUser model class with all the features required by the ASP.NET Core Identity service to use it for auth purposes. Luckily enough, the package comes with a built-in IdentityUser base class that can be used to extend our own, thus granting it all that we need.

To do that, navigate to the /Data/Models/ folder, edit the ApplicationUser.cs file, and update it in the following way:

[...]

public class ApplicationUser : IdentityUser

[...]

Again, this will require a using Microsoft.AspNetCore.Identity on top.

As soon as we apply the changes and save the file, the Visual Studio Error List panel should show three warnings about the UserName, Id, and Email properties of our new model; apparently, these properties are now in conflict with three members already existing in the base class with the same names. As a matter of fact, we did that on purpose when we first created the model back in Chapter 4, Data Model with Entity Framework Core; we knew that this moment would eventually come, hence we named these properties with the exact same names of those being in the UserIdentity base class. Thanks to that decision, we can now fix our model by simply commenting out the offending properties in the following way:

[...]

#region Properties
//[Key]
//[Required]
//public string Id { get; set; }

//[Required]
//[MaxLength(128)]
//public string UserName { get; set; }

//[Required]
//public string Email { get; set; }

public string DisplayName { get; set; }

[...]

Alternatively, we can also entirely delete them; they won't be needed anymore.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.12