Integrating and Using Identity In Asp.Net Core Using Postgre SQL
Today in this tutorial we will have a look at the process of integrating identity in asp.net core with Postgres SQL. Before that let us have a general introduction about postgre and Identity. First of all let us know about postgres. What is Postgres?According to wikipedia Postgre SQL also known as Postgres, is a free and open source relational database management system (RDBMS). It is designed to handle a range of workloads, from single machines to data warehouses or Web Services with many concurrent users. Moreover it is the default database for macOS Server. It is also available for Linux, FreeBSD, OpenBSD, and Windows. for more information please visit https://en.wikipedia.org/wiki/PostgreSQL. Not let us talk about Identity in ASP.NET MVC. Identity is basically a method for providing Authentication and Authorization in a web application. For more information about Identity Please visit https://docs.microsoft.com/en-us/aspnet/identity/overview/getting-started/introduction-to-aspnet-identity . This article is an example of using Identity in postgre SQL. If you want to use Identity in MSSQL please follow the following link: https://www.everestparked.com/post/authentication-in-asp-dot-net-mvc-using-identity . Now, before any delay let's dive into the process of integrating identity in asp.net core/MVC using postgre SQL.
1) First of all open visual studio and create a new project. Here select ASP.NET Core Web Application and then click Next.
2) Next, Select Suitable Name for your project and click Create.
3) Now, Select Web Application(Model-View-Controller) and Change Authentication to Individual User Accounts if it is not selected before and then click Create.
4) After this the project structure might look as shown below:
5) Now, after the project is created let us install the required dependencies for PostgreSQL. So, first of all Open Package manager console and install the following two packages:
5) Now, open Startup.cs file . Here you can see the following configuration which was meant for sql server.
But since we are using postgre SQL we need to perform certain changes as shown below to make our application to use Postgre SQL.
The only change here is the following line of code.
6) Now, let us check our project file. for this right click on your solution and click edit .csproj file as shown below:
Here ensure that the following two highlighted items are present in the file else type it manually.
7) Next, make sure you have ApplicationDbContext class and connection string specified as shown below:
8) Now, that's all we need to do in our application part. Next, we need to run the migration to create the required tables in the database. for that open your package manager console and run the following commands:
9) Now, let us open our postgre SQL Server and here we can see the database and all other identity tables being created, which is shown in following figure:
In this way we Successfully integrated Identity in asp.net core Using Posgre SQL. Please let me know if you have any problems in running this process in the comment section below. I will be more than happy to assist you.