Introduction:

In this article we are going to explain how to use authentication in mvc core or how to create individual authentication in mvc core or how to use ASP.NETCore Identity in MVC Application with example.

Description:

ASP.NET Mvc Core Identity allows us to add login functionality to our system. Here, in this demo, we will be using SQL Server to store the user details and profile data. We will use ASP.NET Identity for new user registration, login, and to maintain the user profile data. If we talk about the login, the important part is whether the logged in user is authenticated and also authorized to view the pages.

Let’s see how to create a simple Login and Register Functionality in ASP.NET Mvc Core.

 

Step 1: We will create a Database and set the connection string in appsettings.json file for DefaultConnection with our new database connection. We will be using this database for ASP.NET Core Identity table creation.

Create Database: Run the following script to create our database.  

Create DataBase TechMindCore

Step 2: Create your ASP.NET Core  

After installing our Visual Studio 2017, click Start, then Programs and select Visual Studio 2017 - Click Visual Studio 2017. Click New, then Project, select Web and then select ASP.NET Core Web Application. Enter your project name and click: 

Use ASP.NET Core MVC Authentication

Select Web Application (Model-View-Controller) and click on Change Authentication

Use ASP.NET Core MVC Authentication

Select Individual User Accounts and click ok to create your project.

Use ASP.NET Core MVC Authentication

Updating appsettings.json 

In appsettings.json  file we can find the DefaultConnection Connection string. Here in connection string change your SQL Server Name, UID and PWD to create and store all user details in one database.

"ConnectionStrings":
{
    "DefaultConnection": "Password=sa@123;Persist Security Info=True;User ID=sa;Initial Catalog=TechMindCore;Data Source=(local)"
  }

 

 Using Package Manager Console

        Go to Tools –> NuGet Package Manager –> Package Manager Console

        And then run the following command below to update database:

 

       PM> Update-Database

 

        After using above commond, check your database will be updated.


 Use ASP.NET Core MVC Authentication

Now Run the application and register a New User.

Use ASP.NET Core MVC Authentication

After Registering, we can User logging.

Use ASP.NET Core MVC Authentication

 

We can see registered user stored in database;

Use the following command to see users from database table in sql server:

select * from AspNetUsers

 

Use ASP.NET Core MVC Authentication

I hope it will help to you after reading it.

 

 

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like