I’m trying my first asp.net mvc 5 project, which more or less forces you to use the new asp.net identity framework for membership. It’s in the using Microsoft.AspNet.Identity namespace.
While a vast improvement over the original asp.net membership – I do not see any massive benefit over the MVC 4 Simple Membership system. Here are 5 things you need to know about the asp.net identity system before you upgrade
- The ID column is stored as a guid, and not an int – One of my favorite things about the simple membership system was being able to use int columns for ID – no more of that
- In the default project, all of the membership tables will be stored in Local DB, even if you change the connection string in the web.config
- MVC introduces a peculiar (to me at least) way of creating the Database tables for membership in the LocalDB – in the IdentityModel.cs file in the Models folder, you will see the following bit of code
public class ApplicationDbContext : IdentityDbContextWithCustomUser
{
}this will create the following tables in the Local DB
- ASPNetUsers
- ASPNeRoles
- ASPNeTokens
- ASPNetUserClaims
- ASPNetUserLogins
- ASPNetUserManagements
- ASPNetUserRoles
- ASPNetUserSecrets
if you are running a separate database you will find it quite confusing to get the membership and the other data in the same context (the error message are rather opaque. To fix the matter, add in the following code in your regular data context class and comment out the ApplicationDbContext : IdentityDbContextWithCustomUser in IdentityModel.cs
public DbSet ApplicationUsers { get; set; }
public DbSet Roles { get; set; }
public DbSet Tokens { get; set; }
public DbSet UserClaims { get; set; }
public DbSet UserLogins { get; set; }
public DbSet UserManagements { get; set; }
public DbSet UserRoles { get; set; }
public DbSet UserSecrets { get; set; }and everything will both be in the same database and the same data context.
- The quick and easy way of getting the User ID (comparable to WebSecurity.CurrentUserID is User.Identity.GetUserID() – that will return the guid of the user.
- It is pleasantly integrated with entity framework code first, and will probably be a positive feature over time.