ASP.NET Core Identity is a new system of user authentication and authorization for ASP.NET Core. You can read more on ASP.NET Identity in Microsoft documentation.
dotConnect for SQLite enables you to employ an implementation of ASP.NET Core Identity for SQLite database using Entity Framework Core functionality in your web applications. This allows you to use such ASP.NET Core Identity benefits as unit-testable user authentication system, social login support, OWIN integration, etc. This tutorial demonstrates creating an Entity Framework implementation of ASP.NET Core Identity.
To complete this tutorial you need Visual Studio 2017 or higher. You may also use Visual Studio 2015 with NET Core tools Preview 2 for Visual Studio 2015 installed, but in this case you may need to install newer versions of Entity Framework Core-related NuGet packages to the project.
If you use the trial version of dotConnect for SQLite, you will also need to install dotConnect for SQLite in order to get the corresponding trial license key file. See more details about technical licensing in .NET Core applications using dotConnect for SQLite in the Licensing .NET Standard (.NET Core) Projects topic.
In order to create an ASP.NET Core application using dotConnect for SQLite for storing identity information, perform the following steps:
FVisual Studio 2019, or Visual Studio 2022: Select C# in the left drop-down list, then select Windows in the middle one, and Web in the right. Then select ASP.NET Core Web Application, click Next, and then click Create.
For Visual Studio 2017: In the Add New Project dialog box expand Visual C# on the left, then Web, and then select ASP.NET Core Web Application (.NET Core). Name your project, for example, "AspNetCore_Identity_Application" and then click OK.
In the next dialog box, select the Web Application (Model-View-Controller) template.
Visual Studio 2019
Visual Studio 2017
FVisual Studio 2019, or Visual Studio 2022, under Authentication, click Change. For Visual Studio 2017, click Change Authentication.
Execute the following command in the Package Manager Console:
install-package Devart.Data.SQLite.EFCore
In the appsettings.json file of your project, replace the default connection string with your SQLite one. For example:
"ConnectionStrings": { "DefaultConnection": "DataSource=mydatabase.db;" },
If you purchased dotConnect for SQLite, add your license key to the connection string as the License Key connection string parameter.
In the Startup.cs file of the application, replace
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
with
options.UseSQLite(Configuration.GetConnectionString("DefaultConnection")));
Execute the following command in the Package Manager Console:
add-migration CreateIdentitySchema -OutputDir Data\Migrations
Execute the following command in the Package Manager Console:
update-database
Now we can run our application and check if everything works correctly.
Using Entity Framework Implementation of ASP.NET Identity 1 for SQLite | Using Entity Framework Implementation of ASP.NET Identity 2 for SQLite | Using ADO.NET Implementation of ASP.NET Identity 1 for SQLite | Using ADO.NET Implementation of ASP.NET Identity 2 for SQLite