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 Oracle enables you to employ an implementation of ASP.NET Core Identity for Oracle 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 Oracle, you will also need to install dotConnect for Oracle in order to get the corresponding trial license key file. See more details about technical licensing in .NET Core applications using dotConnect for Oracle in the Licensing .NET Standard (.NET Core) Projects topic.
In order to create an ASP.NET Core application using dotConnect for Oracle for storing identity information, perform the following steps:
-
For Visual Studio 2019: 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
For Visual Studio 2019, under Authentication, click Change. For Visual Studio 2017, click Change Authentication.
- Then select Individual User Accounts as authentication method and click OK.
-
Execute the following command in the Package Manager Console:
install-package Devart.Data.Oracle.EFCore
In the appsettings.json file of your project, replace the default connection string with your Oracle one. For example:
"ConnectionStrings": { "DefaultConnection": "User Id=Scott;Password=tiger;Data Source=Ora;" },
If you purchased dotConnect for Oracle, 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.UseOracle(Configuration.GetConnectionString("DefaultConnection")));
- In the Solution Explorer open the Data\Migrations folder and delete all its content.
-
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
Checking Application
Now we can run our application and check if everything works correctly.
- Run the application by pressing CTRL+F5.
- Switch to the Register tab on the top of the page.
- Enter a new Email and password to the corresponding boxes and click the Register button.
- The new user is now registered and logged in, and the ASP.NET Identity tables are created in the Oracle database.
- After this you may use an appropriate database tool to connect to the database where the user data is stored and verify that the data is stored correctly.
See Also
Using Entity Framework Implementation of ASP.NET Identity 1 for Oracle | Using Entity Framework Implementation of ASP.NET Identity 2 for Oracle | Using ADO.NET Implementation of ASP.NET Identity 1 for Oracle | Using ADO.NET Implementation of ASP.NET Identity 2 for Oracle