Aspidentity 2.2 (framework 4.x) reused on AspnetCo

2019-08-30 01:50发布

问题:

Existing : aspnet webapp and dB, using aspidentity to [Authorize] on controllers

New: AspnetCore app, how to use the 'old' aspidentity DB to Authorize?

回答1:

AspNet solution:

  1. DB update: https://github.com/CK159/CoreXplore/tree/master/Db/Migrations/Identity2Core

  2. Add migration for new columns.

  3. Update new AspNetUsers ApplicationUser class properties: ConcurrencyStamp = System.Guid.New(); NormalizedEmail = Email.Upper(); NormalizedUserName = Email.Upper();
  4. Update new ApplicationUser with new properties and default values

AspNetCore solution:

  1. Configure aspnetcore PasswordHasher use V2 options in compatibility mode. V3 login on the AspNetCore solution, user can not login on the AspNet solution: by services.Configure<PasswordHasherOptions>(o => o.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);
  2. Connection string point to Existing DB
  3. Deploy in same WebApp 'host' as Exiting WebApp on Azure, that way it will share the same machine key (not completely sure this is necessary).