Identityazuretable
This project provides a high performance cloud solution for ASP.NET Identity Core using Azure Table storage replacing the Entity Framework / MSSQL provider.
Quick Start: IdentityCore 2.x PageModel Scaffolding
ElCamino.AspNetCore.Identity.AzureTable
Sample Core MVC with Identity PageModel Scaffolding Website
Included in the source is a MVC Core Website project that is an example of removing the EntityFramework and Identity EntityFramework references and replacing them with the Azure Table storage provider. It was created by using the Scaffold Identity in ASP.NET Core projects process as a starting point.
Overview
The sample Mvc web application is a standard web application that uses the Individual User Accounts authentication type. The EntityFramework references have been removed and replaced with the Azure Table storage provider.
Walk-Through of the samplemvccore3
Remove the NuGet packages EntityFramework and Microsoft.AspNetCore.Identity.EntityFramework packages using the Manage NuGet Packages.
Note
Remove this using statement throughout the application.
using Microsoft.AspNetCore.Identity.EntityFramework;
Add the NuGet package or the assembly ElCamino.AspNetCore.Identity.AzureTable to the web application.
Simplify project references
<ItemGroup>
<PackageReference Include="ElCamino.AspNetCore.Identity.AzureTable" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>
Changes to /sample/samplemvccore3/Models/ApplicationUser.cs
Note
Replace the statements
using Microsoft.AspNetCore.Identity.EntityFramework;
using Microsoft.AspNetCore.Identity;
with:
using ElCamino.AspNetCore.Identity.AzureTable.Model;
Inherit from the lightweight IdentityUserV2 (follow all V2 implementation) class to provide the base user information and Azure Table Row and Partition Key mappings.
// You can add profile data for the user by adding more properties to your ApplicationUser class.
public class ApplicationUser : IdentityUserV2
{ ...
Changes to /sample/samplemvccore3/Data/ApplicationDbContext.cs
Note
Replace the statement
using Microsoft.AspNetCore.Identity.EntityFramework;
with:
using ElCamino.AspNetCore.Identity.AzureTable;
using ElCamino.AspNetCore.Identity.AzureTable.Model;
Inherit from the IdentityCloudContext which provides the Azure connection and table storage schema.
public class ApplicationDbContext : IdentityCloudContext
{
public ApplicationDbContext() : base() { }
public ApplicationDbContext(IdentityConfiguration config) : base(config) { }...
Changes to /sample/samplemvccore3/Startup.cs
Note
Replace the statement
using Microsoft.AspNetCore.Identity.EntityFramework;
with:
using ElCamino.AspNetCore.Identity.AzureTable;
using ElCamino.AspNetCore.Identity.AzureTable.Model;
Adding code to inject the Azure table provider into the Identity middleware pipeline and optionally, create the azure tables. Remove any EntityFramework extension methods here.
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
// Add Elcamino Azure Table Identity services.
services.AddIdentity()
.AddAzureTableStoresV2(new Func(() =>
{
IdentityConfiguration idconfig = new IdentityConfiguration();
idconfig.TablePrefix = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:TablePrefix").Value;
idconfig.StorageConnectionString = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:StorageConnectionString").Value;
idconfig.LocationMode = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:LocationMode").Value;
//Setting TableNames is optional, default value shown below if not set.
idconfig.IndexTableName = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:IndexTableName").Value; // default: AspNetIndex
idconfig.RoleTableName = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:RoleTableName").Value; // default: AspNetRoles
idconfig.UserTableName = Configuration.GetSection("IdentityAzureTable:IdentityConfiguration:UserTableName").Value; // default: AspNetUsers
return idconfig;
}))
.AddDefaultTokenProviders()
.AddDefaultUI(UIFramework.Bootstrap4)
.CreateAzureTablesIfNotExists(); //can remove after first run;
services.AddMvc();
// Add application services
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
...
Changes to /sample/samplemvccore3/appsettings.json
Remove all references to the EntityFramework.
Add the default local connection string to the Azure Storage Emulator in the appsettings.json. TablePrefix can be left blank, any text here will prefix the Azure table storage names. StorageConnectionString is the Azure table storage connection string. LocationMode can be left empty (defaults to PrimaryOnly). Other storage location modes are listed here and must be used with a RA-GRS storage account if changed from the default. *TableName values can be null or left empty and default values are shown in the example below.
{
...
"IdentityAzureTable": {
"IdentityConfiguration": {
"TablePrefix": "v2"
"StorageConnectionString": "UseDevelopmentStorage=true;"
"LocationMode": "PrimaryOnly"
"IndexTableName": "AspNetIndex"
"RoleTableName": "AspNetRoles"
"UserTableName": "AspNetUsers"
}
}...
}
Tip
Don't forget to start your Azure Storage Emulator if running locally.
A blog for modern software development
Software as a Service
Optic Nerve AI
No code, first class import/publish with Azure, Google cloud custom vision AI services.