Introduction
Adding security to your application is an important step. So that you allow only authenticated users to access the application. ASP.NET Core Identity is a powerful system that simplifies user authentication in ASP.NET Core applications. It provides a wide range of features, including user registration, login, password management, role-based authorization, and integration with external authentication providers.
In this article, you will learn how to add identity service to your ASP.NET 6 MVC project. Before getting started, let's see the basics.
What is ASP.NET Core MVC?
ASP.NET Core MVC is a powerful and flexible framework for building web applications using the ASP.NET Core platform. MVC separates the application into three different components: the model, the view, and the controller. The model represents the application's data and business logic. It encapsulates the data structures, logic, and algorithms necessary to manipulate and process the data. The view is responsible for presenting the user interface to the users. The view receives data from the model and renders it in a user-friendly format. The controller acts as the intermediary between the model and the view. The controller handles the flow of the application by receiving requests, processing them, and returning the appropriate response.
What is authentication and authorization?
Authentication and authorization are crucial aspects of application development. Authentication refers to the process of verifying the Identity of users, ensuring that they are who they claim to be. Authorization, on the other hand, is the process of granting or denying access to specific resources or functionalities based on the authenticated user's permissions and roles.
In today's digital landscape, where sensitive user data and confidential information are involved, it is essential to implement a secure authentication and authorization mechanism. It helps protect user accounts, restrict unauthorized access to sensitive data, and ensure that only authorized users can perform certain actions within the application. By implementing authentication and authorization effectively, developers can enhance the overall security and trustworthiness of their web applications.
What is ASP.NET Core Identity?
ASP.NET Core Identity is a membership system that provides built-in support for user authentication and authorization in ASP.NET Core applications. It simplifies the process of managing user accounts, passwords, and roles, allowing developers to focus on the core functionality of their applications.
In other words, ASP.NET provides the required functionality to add functionality like registering, signing in, signing out, managing users, passwords, profiles, authorization, roles, claims, tokens, email confirmation, and much more.
ASP.NET Core Identity offers a robust set of features, including user registration, login, password management, role-based authorization, and external authentication provider integration. It seamlessly integrates with ASP.NET Core MVC, making it easy to incorporate authentication and authorization capabilities into your web application.
With ASP.NET Core Identity, developers can leverage secure authentication mechanisms like cookies and JSON Web Tokens (JWT). It also provides a flexible and extensible architecture that allows customization and integration with existing user stores and providers. Whether you're building a small-scale application or a large enterprise-level system, ASP.NET Core Identity provides the necessary tools and APIs to implement secure and scalable authentication and authorization solutions.
Prerequisites
- Visual Studio 2022
- .NET 6 Framework
- MS SQL Server
How to Set up ASP.NET Core Identity In Our Project?
To do authentication using Identity, I will create the project from scratch. Now, let's create the project.
Step 1. Creating the project
Open Visual Studio 2022. Select "Create a new project" and click "Next". Select the "ASP.NET Core Web App (Model-View-Controller)" template and click on "Next".

Name your project and solution as you wish and select the location where you want to store your project, and click on "Next". We have named our project "CRMApp".
Choose the "NET 6" framework and click on the "Create" button.

Now, you have successfully created the project.
Step 2. Setting up the database
Open SSMS (SQL Server Management Server) and create and use a database.
create database SalesCRM;
use SalesCRM;
Step 3. Open appsetting.js and set the connection string.
"ConnectionStrings":
{
"SalesCRMcnn": "Server=***;Database=SalesCRM;User Id=**;Password=****;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
}
Step 4. Creating Models
Click on Models and add a new class named SalesleadEntity.cs. In this class, add the required properties for the model as shown below.
namespace CRMApp.Models
{
public class SalesLeadEntity
{
public int Id { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? Mobile { get; set; }
public string? Email { get; set; }
public string? Source { get; set; }
}
}
Step 5. Adding Required Packages
Now, Right click on the project and select "Manage NuGet Packages". In the browse section, search the following packages and install them.
- Microsoft.EntityFrameworkCore
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Tools
- Microsoft.AspNetCore.Identity.EntityFrameworkCore








Ravindra GuptaPosted Jan 15, 2024, 12:08 PM
Nice Articles.
kishore kumarPosted Sep 21, 2023, 8:23 AM
How to implement for existing database?
Waleed AmjadPosted Sep 19, 2023, 11:38 AM
Thankyou soo much for this amazing up to date guide!