Identityazuretable
This project provides a high performance cloud solution for ASP.NET Identity Core using Azure Table storage replacing the Entity Framework / MSSQL provider.
IdentityCore 3.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 samplemvccore4
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="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
</ItemGroup>
Changes to /sample/samplemvccore4/areas/identity/**.cs
Remove and add statements
Note
Replace the statement
using Microsoft.AspNetCore.Identity.EntityFramework;
with:
using IdentityUser = ElCamino.AspNetCore.Identity.AzureTable.Model.IdentityUser;
Changes to /sample/samplemvccore4/**/**/_ViewImports.cshtml
Add this using to override the IdentityUser class in the Microsoft.AspNetCore.Identity namespace
@using IdentityUser = ElCamino.AspNetCore.Identity.AzureTable.Model.IdentityUser
Changes to /sample/samplemvccore4/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/samplemvccore4/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.AddDbContext(options =>
// options.UseSqlServer(
// Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options =>
{
// Set whatever identity options here
options.SignIn.RequireConfirmedAccount = true;
options.User.RequireUniqueEmail = true;
})
.AddAzureTableStores<ApplicationDbContext>(new Func<IdentityConfiguration>(() =>
{
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()
.CreateAzureTablesIfNotExists<ApplicationDbContext>(); //can remove after first run;
//.AddEntityFrameworkStores<ApplicationDbContext>();
// Add application services
...
Changes to /sample/samplemvccore4/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.