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 MVC - No PageModel Scaffolding
ElCamino.AspNetCore.Identity.AzureTable
Sample Mvc6 (.NET Core 2) Website
Included in the source is a MVC 6 Website project that is an example of removing the EntityFramework and Identity EntityFramework references and replacing them with the Azure Table storage provider.
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 samplemvccore2
Remove the NuGet packages EntityFramework and Microsoft.AspNetCore.Identity.EntityFramework packages using the Manage NuGet Packages.
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.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
Changes to /sample/samplemvccore2/Models/ApplicationUser.cs
Replace the statement
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.
Use the IdentityUser class if you prefer to carry the Role, Claims, Logins and Token collections around.
// You can add profile data for the user by adding more properties to your ApplicationUser class.
public class ApplicationUser : IdentityUserV2 // or IdentityUser
{ ...
Changes to /sample/samplemvccore2/Data/ApplicationDbContext.cs
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/samplemvccore2/Startup.cs
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()
// User this .AddAzureTableStores method if you are using the IdentityUser.
// .AddAzureTableStores(new Func(() =>
.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;
return idconfig;
}))
.AddDefaultTokenProviders()
.CreateAzureTablesIfNotExists(); //can remove after first run;
services.AddMvc();
// Add application services
Changes to /sample/samplemvccore2/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.
{
...
"IdentityAzureTable": {
"IdentityConfiguration": {
"TablePrefix": "mvc6"
"StorageConnectionString": "UseDevelopmentStorage=true;"
"LocationMode": "PrimaryOnly"
}
}...
}
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.