Introduction
Microsoft has released the latest version for the ASP.NET Identity, ASP.NET Identity 2.0.0-alpha1. There are two new features in this version to the IdentityUser named "Email" and "IsConfirmed" as I described in the Introduction to ASP.NET Identity 2.0.0.
In that context, in this article you will see the migration process to 2.0.0-alpha1 from 1.0.0 version of ASP.NET Identity. We create this application with the ASP.NET Identity 1.0.0 version and create a new user registration for the application and next we'll make the change after upgrading the Identity to 2.0.0-aplha1.
Use the following procedure to create a sample.
Application Creation
Step 1: Open Visual Studio 2013 and create a new project.
Step 2: Select the Project template, either Web Forms or MVC as shown below:
Step 3: Run the application and register the new user:
Now you'll see that the user registration is successful and back to the Home page. This step is analogous to users having used ASP.NET Identity 1.0.0 bits for user and role management.
Updating Identity
Step 4: Now just right-click on the project to open the Manager NuGet Packages.
Step 5: Go to the Updates section on the left pane and update the ASP.NET Identity packages.
Step 6: After updating the packages, you can see the updated packages.config file:
Step 7: Now run the application and login through the registered user and you would see the following Server Error in your application.
Enable Migration
Since the model has been changed you need to enable and add the migration. Use the following procedure to do that.
Step 8: Open the Package Manager Console and enter the following command:
Enable-Migrations
Step 9: Now enter the following command in the Package Manager Console:
add-migration update1
It'll generate the following update1 class:
namespace NewIdentityDemoApp.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class update1 : DbMigration
{
public override void Up()
{
RenameColumn(table: "dbo.AspNetUserClaims", name: "User_Id", newName: "UserId");
AddColumn("dbo.AspNetUsers", "Email", c => c.String());
AddColumn("dbo.AspNetUsers", "IsConfirmed", c => c.Boolean(nullable: false));
AlterColumn("dbo.AspNetUsers", "UserName", c => c.String(nullable: false));
DropColumn("dbo.AspNetUsers", "Discriminator");
}
public override void Down()
{
AddColumn("dbo.AspNetUsers", "Discriminator", c => c.String(nullable: false, maxLength: 128));
AlterColumn("dbo.AspNetUsers", "UserName", c => c.String());
DropColumn("dbo.AspNetUsers", "IsConfirmed");
DropColumn("dbo.AspNetUsers", "Email");
RenameColumn(table: "dbo.AspNetUserClaims", name: "UserId", newName: "User_Id");
}
}
}
Step 10: Now enter the following command again in the console:
update-database -verbose
The verbose flag lets you view the SQL queries generated. Now the migration process is complete and there is no issue to login with the registered user in the application.
Summary
This article has introduced you to the new ASP.NET Identity version and also how to migrate to the new version from the old version of ASP.NET Identity. Thanks for reading.