1

ASP.NET Identity OWIN with Entity Framework adds the following tables to the database:

ASPNetUsers
ASPNeRoles
ASPNeTokens
ASPNetUserClaims
ASPNetUserLogins
ASPNetUserManagements
ASPNetUserRoles
ASPNetUserSecrets
  1. Can someone explain to me where these names come from? I scoured my solution and project files and see no reference to them. Are these names customizable (I mean when they're generated--not after they exist in the database)?

  2. I tried an experiment and added a new project to my ASP.NET MVC 5 solution. I then used NuGet to install Microsoft ASP.NET Identity Owin. I then added Entity Framework 6 to that project and created a datacontext class that inherits from DbContext. At that point, I ran the "enable-migrations" command from the Package Manager Console. That created a Migrations folder and a migration class as well as a Configuration.cs class. So far, so good. But when I ran the "add-migration initial" command, none of the ASP.NET Identity tables mentioned above are generated.

    Yet when I follow the same steps in my MVC project, however, the add-migration command does generate the above tables. In my MVC project, there is a startup.auth.cs class in my App_Start folder, however. That seems to be the key but I'm just not sure because something is "auto-magically" happening that I clearly don't understand. The startup.auth.cs file looks like this:

.

using Microsoft.AspNet.Identity;    
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;

namespace AspNetIdentity
{
    public partial class Startup
    {
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
        }
    }
}

If I want to be able to migrate the ASP.NET Identity tables from a project other than my MVC project, how can I do that?

Community
  • 1
  • 1
Jazimov
  • 12,626
  • 9
  • 52
  • 59
  • possible duplicate of [How can I change the table names when using Visual Studio 2013 AspNet Identity?](http://stackoverflow.com/questions/19460386/how-can-i-change-the-table-names-when-using-visual-studio-2013-aspnet-identity) – jamesSampica Feb 14 '14 at 14:22
  • I beg to differ: Asking how to change the table names is not the same question as asking from where those names come/originate. Also, my question segues to asking about decoupling, which is not a duplicate of the question cited. – Jazimov Feb 14 '14 at 15:31
  • The answer might be subtle, but the answer has you override `System.Data.Entity.DbModelBuilder` entities. I think it can be inferred that the default table names reside there. You can use a decompiler to confirm – jamesSampica Feb 14 '14 at 15:41
  • I asked "where are they"--not "how can I use a decompiler to reverse-engineer Microsoft's code and figure out what's going on". Therefore, I don't consider this an answer to my question. – Jazimov Feb 14 '14 at 20:19

1 Answers1

0

Note: these tables names look to be from a prerelease version of Identity 1.0, but the short answer is, they come from IdentityDbContext.OnModelCreating which specifies the table names for the various entities.

Your IdentityDbContext is usually passed into the UserStore. Wherever you are creating your UserManager, that is likely where you are constructing both the UserStore and the IdentityDbContext. Note that the default constructor for UserStore creates a new IdentityDbContext which uses the "DefaultConnection" string, so that could be the magical step that you are not seeing.

IdentityDbContext

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
Hao Kung
  • 28,040
  • 6
  • 84
  • 93