logo
logo
Sign in

The Intermediate Guide to Setting Up ASP.NET Core Identity

avatar
meenati biswal
The Intermediate Guide to Setting Up ASP.NET Core Identity

The process for setting up Identity touches on almost every part of an application, requiring new model classes, configuration changes, and controllers and actions to support authentication and authorization operations.

 

 In the sections that follow, I walk through the process of setting up Identity in a basic configuration to show the different steps that are involved. There are lots of different ways of using Identity in an application, and the configuration I use in this chapter follows the simplest and most commonly used options.

 

Creating the User Class The first step is to define a class to represent a user in the application, which is known as the user class. The user class is derived from IdentityUser, which is defined in the Microsoft.AspNetCore.Identity namespace. IdentityUser provides the basic user representation, which can be extended by adding properties to the derived class the most useful built-in properties that IdentityUser defines.

 The Properties Defined by the IdentityUser Class 

 

Name Description

Id _ This property contains the unique ID for the user. 

UserName _ This property returns the user’s username

Claims This property returns the collection of claims for the user

Email _ This property contains the user’s e-mail address. 

Logins _ This property returns a collection of logins for the user, which is used for third-party authentication

PasswordHash_ This property returns a hashed form of the user password, which I use in the “Implementing the Edit Feature” section. 

Roles _ This property returns the collection of roles that the user belongs to

PhoneNumber _This property returns the user’s phone number. SecurityStamp_ This property returns a value that is changed when the user identity is altered, such as by a password change.

 

The individual properties don’t matter at the moment. What’s important is that the IdentityUser class provides access to basic information about a user: the user’s name, e-mail, phone number, password hash, role memberships, and so on. If I want to store any additional information about the user, I have to add properties to the class that I derive from IdentityUser and that will be used to represent users in my application. To create the user class for my application, I created the Models folder and added a class file called AppUserModels.cs that I used to create the app user class.

 

The Contents of the AppUser.cs File in the Models Folder

using Microsoft.AspNetCore.Identity;

namespace Users.Models {

    public class AppUser : IdentityUser {       

 // no additional members are required        

// for basic Identity installation   

 } 

}

That’s all I have to do at the moment when I show you how to add application-specific user data properties.

Learn more about asp.net core at Visual Studio Training 

 

collect
0
avatar
meenati biswal
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more