Implementing authentication using ASP.NET Core Identity and customizing the Identity data store

In this section, we will implement ASP.NET Core Identity in an ASP.NET Core MVC application. This section will cover all the details on configuring the Identity and adding functionality to register, log in and log out, and modify the default data store to save some other information of the user and implement authorization in a simple web application that does not have a service layer in terms of a Web API.

The ASP.NET Core application can be created either through Visual Studio 2015 or a greater version, or it can also be created using the .NET CLI or Yeoman command-line tools. When creating an ASP.NET Core web application, you have a choice to select the specific service accounts:

When you click on the Change Authentication dialog, it opens up the dialog to select the type of authentication you want to use and configure your web application, shown as follows:

The following table shows the details of each authentication type:

Authentication Type Description
No Authentication If no authentication is required
Individual User Accounts To store the user profile in a database and bring authentication to the user store and external authentication providers
Work and School Accounts To authenticate users with Active Directory, Microsoft Azure, Active Directory, or Office 365
Windows Authentication For intranet applications

When you select the Web Application option as a project type and select any of the preceding authentication types from individual accounts, work and school accounts, or windows authentication, Visual Studio adds some boilerplate code into your project that has all the basic configuration, as per the selected authentication type. AccountController is created to perform user registration, log in or log off users, and ManageController is created to manage logins, add phone numbers, and more.

By default, the Web application project is configured to use the localdb store to save user information and other information into the database, but this can be modified and the corresponding database connection string can be specified from the appsettings.json file, as shown in the following screenshot:

After running your application, you will see the default website loaded and it should contain options to register and log in as a user:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.9.148