Skip to content

how to change the identity table name and then customize user and role #2

Description

@rakib33

I follow your AspNet-Identity-2-Extending-Users-And-Roles tutorial and it working fine .But i wanted to change my Identity table name.I wrote the code as below
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext()
: base("DefaultConnection")
{

    }
    protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<IdentityUser>().ToTable("user");
        modelBuilder.Entity<ApplicationUser>().ToTable("user");

        modelBuilder.Entity<IdentityRole>().ToTable("role");
        modelBuilder.Entity<IdentityUserRole>().ToTable("userrole");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("userclaim");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("userlogin");
    }
}

it changes identity table name.but create a problem in userroles table an extra column added [IdentityUser_Id] NVARCHAR (128) NULL, and when i add user and user role no data added in this field .and [authorize(Role="Admin,User")] always return log in page .how can it solved ?please give suggession? the userroles table script is below:
CREATE TABLE [dbo].[userrole]([UserId] NVARCHAR %28128%29 NOT NULL,
[RoleId] NVARCHAR %28128%29 NOT NULL,
[IdentityUser_Id] NVARCHAR %28128%29 NULL,
CONSTRAINT [PK_dbo.userrole] PRIMARY KEY CLUSTERED %28[UserId] ASC, [RoleId] ASC%29,
CONSTRAINT [FK_dbo.userrole_dbo.mcms_role_RoleId] FOREIGN KEY %28[RoleId]%29 REFERENCES [dbo].[role] %28[Role_ID]%29 ON DELETE CASCADE,
CONSTRAINT [FK_dbo.mcms_userrole_dbo.mcms_user_IdentityUser_Id] FOREIGN KEY %28[IdentityUser_Id]%29 REFERENCES [dbo].[user] %28[User_ID]%29);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions