Brains Coders

Brains Engineering Blog

Asp.Net Identity 2 - Rename Tables and Fields

Just the other day I decided to migrate from the old and reliable Custom Membership Provider to the new Asp.Net Identity 2.0 

Mainly for two reasons: I want to integrate social login, and I want to be ready to move to vNext when it will be stable enough to be used in production.

I've started looking at the demo project by Microsoft "WingtipToys", you can download it from here

In order to start with Asp.Net Identity 2, you need to download some packages from NuGet and install them in your new or existing project:

  • Microsoft.AspNet.Identity.EntityFramework
  • Microsoft.AspNet.Identity.Core
  • Microsoft.AspNet.Identity.OWIN

Changing Tables and Fields name

Personally I don't like the naming convention of SQL Tables: AspNetUsers, AspNetRoles,... no way.
So I stucked into the hard process of changing, hard if you don't know how to do.

First of all, to change tables and fields names, you must have created a "Web Project" and not a "Web Site" in Visual Studio.
Why? because you have to install migration for Entity Framework Code First, as the identity SQL tables are created from the code that is in the compiled dll you have previously installed with NuGet.

In order to properly modify the tables and fields name you must add the following code in the onModelCreating of your application DB context: 

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    base.OnModelCreating(modelBuilder); // This needs to go before the other rules!


Please note that I have changed the class name ApplicationUser into User, adding some fields to it:

public class User : IdentityUser
    public string Description { get; set; }
    public int OrganizationId { get; set; }
    public string FirstName { get; set; }
    public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
        //Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    public Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
        return Task.FromResult(GenerateUserIdentity(manager));

Comments (1) -

  • xK4OAG0PtZTq

    11/26/2017 6:27:16 AM | Reply

    174613 937343An really intriguing examine, I may possibly not agree completely, but you do make some quite legitimate factors. 234835