Create User in ASP.NET Core – Session 60

Create-User-ASPNET-Core-Session 60

During this session, we are going to create a user in ASP.NET Core with Identity Entity Framework Core. For this purpose, we use UserManager Class from Microsoft.AspNetCore.Identity. In Session 59, we added Microsoft.AspNetCore.Identity.EntityFrameworkCore to our project and added the Identity entities to our project. Now we start the authentication process by creating a user that can log in (authenticate) to our web app.

Create a Controller for User Management

First, we need to create a controller to handle the user management process. also, we create an action method for creating a user, which we call it CreateUser.

Also, we need to inject UserManager class into the controller for handling create user process.

As you can see, the Action Method was decorated with [HttpGet] and returned a view that we create later. Also, we need to inject UserManager class into the controller for handling create user process.

Next, we need a ViewModel which transfers data between View and Controller.

The ViewModel has three properties (Email, Password, and ConfirmPassword) that have the required data annotation. If you need to know more about these data annotations, you can watch Session 38, Session 39, and Session 40.

View and Action Method For Creating User

At this stage, we need to create a View which has a form and use CreateUserViewModel ViewModel.

Then, as you can see the form is submitted with the Post method and we need to create an HTTP POST action method for CreateUser Action Method into UserManagment Controller.

As shown above, we use UserManager to create a user which needs an object of IdentityUser. Also, we store the result of the CreateAsync method in an object to check whether the user is created or not.

In the end, we add an item to the main menu which calls CreateUser Action Method of UserManagment Controller.

If you need more details, watch this session video. Also, to be updated about our coming sessions, follow us on Instagram, Facebook, Telegram, or YouTube. Moreover, you can have access to the list of all sessions HERE and you can download this session source code from our GitHub.

You can download this Session Slides form HERE.

0.00 avg. rating (0% score) - 0 votes


0 0 votes
Article Rating

Inline Feedbacks
View all comments