Welcome to my new post, dear cyber friends, this post will be my first tutorial step by step, enjoy it!
What is Identity Framework?
Identity is a framework to manage the membership of an application, roles, and authentication. Was introduced since 2005 with the welcome back ASP.NET 2.0.
What Identity can do?
userby Email and password.
- Confirm email after register
- Assign roles to Users
- Register through social network
- Among others…
The first thing that we gonna do is create a project:
After selecting the MVC template, change the authentication mode, the application will be configured to use ASP.NET Identity:
That is all. Now you have Identity configured on dot net core project.
If you run the project, you’ll see a default login and register template, but that template isn’t inside the solution as a file, because this template is auto-generated and located in a DLL in your project called “Microsoft.AspNetCore.Identity.UI.Views.V3.dll“, so… how can we edit this template?
Changing the default Identity’s template
- From Solution Explorer, right-click on the Project > Add > New Scaffolded Item.
- Select Identity option > Add
- Select the View that you want override, Select the context and click Add.
Adding new field to the Identity tables
If we want to add a new field that not appear in the template is too easy, for example, we going add the Age of the user on the register page.
- Les’t to create a new POCO (Plain old CLR objects) to add the property to the users.
Add all properties that you gonna use and implement from IdentityUser
2. Change the Generic class that expect our IdentityDbContext with the new User class that we’ve created.
Change the default identity with the new user class on Startup.cs file
even in your _Loginpartial.cshtml file and every single file that you use SignInManager and UserManager class.
3. Create the migration and update the database
4. Modify the ViewModel and View
That is all, run the project and try!
I hope that you’ve enjoyed this post and learned something new, y’all are my incentive.
Sorry for the wait, I’ll post an article every 2 weeks!