6

Right, so..I think I'm confused!!

I have a few ASP.NET MVC 5 sites running using ASP.NET Identity 2.1 and everything is great. I am creating a new MVC 6 site and I would like the users to use there existing credentials that they use for other systems. I have already tried the below:

  1. Migrating the ASP.NET identity 2 database to 3 (says it cannot as the tables already exist, I thought it would migrate the users in all honesty)
  2. Tried getting MVC 6 to work with ASP.NET Identity 2.1 and failed miserably

I am just wondering what my options are since the documentation is not great on the new version, I get that there are DDL changes in the DB but I was kind of hoping there would be a way for my MVC 5 websites to carry on going as is with the .NET Identity 3 database being backwards compatible with 2.1.

My other option is to upgrade the MVC 5 apps to use Identity 3 which in turn I believe means updating them to MVC 6, which is something I don't really have the resources for, or to have a totally new Identity database (which seems the least fuss option).

Any opinions would be helpful, no doubt I have missed out some detail so happy to fill in the blanks should anyone have any further questions about the setup.

MrKobayashi
  • 859
  • 2
  • 11
  • 18

3 Answers3

3

I was doing the same thing, its a good deal of effort - and you will have to run db migrations, but first

The new ASP Identity V3 Tables & Migration

The ASP Identity V3 Tables &  Migration

The new ASP Identity V3 Fields

The fields inside the users table, you can extend this, see below

Configuring the tables In Startup.cs and change services.AddIdentity

   services.AddIdentity<ApplicationUser, IdentityRole<int>>()
    .AddEntityFrameworkStores<ApplicationDbContext, int>()
    .AddDefaultTokenProviders();

In ApplicationContext.cs and change the class to the following signature.

 public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<int>, int>

In ApplicationUser.cs and change the class to the following signature.

`public class ApplicationUser : IdentityUser<int> {...}`
  • Given all the changes I found it easier to delete everything in the migrations folder (except the migrations). Go to command prompt on the directory of the project and type/add a migration like so dotnet ef migrations add MyDatabaseHere -o Data\Migrations. (-o Option is to specify target folder and not root folder)
  • for any issues with migration I would simply drop the database and just deploy again.
  • or you can automate with this I have not tried this

I got two migration scripts from EF, I was not sure why... but for more references from github links 1 & 2

Transformer
  • 3,100
  • 17
  • 40
2

Implement IdentityServer3, it can hook directly into your existing ASP.Net Identity EF DB. Then use the other sites as oAuth clients, being MVC 5 and/or MVC 6 it wont matter because all they will be doing is passing secure tokens back and forth between your IdentityServer3 site.

John C
  • 1,480
  • 1
  • 16
  • 28
1

You can use identity 2 in Asp.Net Core and mantain the passwordhash in the database.Just add this code in startup.cs

 services.Configure<PasswordHasherOptions>(options => {
          options.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2;
      });
Adrian
  • 589
  • 5
  • 10