ASP.NET Identity 2 to 3
Asked Answered
V

3

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.

Voltz answered 21/4, 2016 at 8:49 Comment(0)
A
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

Arellano answered 18/1, 2017 at 20:5 Comment(0)
L
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.

Luddite answered 18/6, 2017 at 5:10 Comment(0)
E
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;
      });
Evaluate answered 26/6, 2018 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.