Using ASP.NET identity in a new app I need code review for using ASP.NET Identity in a new app.

Goals:


Use int instead of GUID for IDs.
Separate identity from view layer


I need code review if I did everything right. Yes it is working but maybe I did something that I shouldn't or maybe there is some place for improvement.

ApplicationUser

public class ApplicationUser : IdentityUser&lt;int, CustomUserLogin, CustomUserRole,
    CustomUserClaim&gt;
    {
        public ICollection&lt;ProductCategory&gt; ProductCategories { get; set; }
        public ICollection&lt;Store&gt; Stores { get; set; }
        public ICollection&lt;Product&gt; Products { get; set; }

        public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(
    UserManager&lt;ApplicationUser, int&gt; manager)
        {
            var userIdentity = await manager.CreateIdentityAsync(
                this, DefaultAuthenticationTypes.ApplicationCookie);            
            return userIdentity;
        }
    }

    public class CustomUserRole : IdentityUserRole&lt;int&gt; { }
    public class CustomUserClaim : IdentityUserClaim&lt;int&gt; { }
    public class CustomUserLogin : IdentityUserLogin&lt;int&gt; { }

    public class CustomRole : IdentityRole&lt;int, CustomUserRole&gt;
    {
        public CustomRole() { }
        public CustomRole(string name) { Name = name; }
    }

    public class CustomUserStore : UserStore&lt;ApplicationUser, CustomRole, int,
        CustomUserLogin, CustomUserRole, CustomUserClaim&gt;
    {
        public CustomUserStore(ApplicationDbContext context)
            : base(context)
        {
        }
    }

    public class CustomRoleStore : RoleStore&lt;CustomRole, int, CustomUserRole&gt;
    {
        public CustomRoleStore(ApplicationDbContext context)
            : base(context)
        {
        }
    }


DbContext

public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser, CustomRole,
    int, CustomUserLogin, CustomUserRole, CustomUserClaim&gt;
    {
        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }

        public ApplicationDbContext()
            : base("DefaultConnection")
        {...


View models are still in view layer. All above is in data layer (class library).
In the view assembly in AccountController I changed all ApplicationUser to reference ApplicationUser in data layer assembly.

I also added extension to get UserID as int:

public static int GetUserIdInt(this IIdentity identity)
        {
            if (identity == null)
                throw new ArgumentNullException("identity");

            string stringUserId = identity.GetUserId();

            int userId;
            if (string.IsNullOrWhiteSpace(stringUserId) || !int.TryParse(stringUserId, out userId))
            {
                return default(int);
            }

            return userId;
        }
Your customization looks fine - that's the way it is recommended to do it.

The only note I could add is about your GetUserIdInt method which you can get rid of. You can just use this generic overload:

User.Identity.GetUserId&lt;int&gt;()