English 中文(简体)
如何将默认 AspNetUser Logins 表格更改为 Blazor 网络应用程序中的 MyUser Logins 表格? NET 8, 以个人账户登录?
原标题:How can I change default AspNetUserLogins table to MyUserLogins table in Blazor web app on .NET 8, Login with individual account?
I created a Blazor web app with authentication type = Individual Account. It automatically maps to the default ASP.NET tables. Can I change the name of these tables to make it maps with my tables in database? Blazor web app settings ASP.NET default tables I tried changing the ApplicationDbContext, but it does not work: public class ApplicationDbContext(DbContextOptions options) : IdentityDbContext(options) { protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().ToTable("MyUsers"); modelBuilder.Entity().ToTable("MyRoles"); modelBuilder.Entity>().ToTable("MyRoleClaims"); modelBuilder.Entity>().ToTable("MyUserClaims"); modelBuilder.Entity>().ToTable("MyUserLogins"); modelBuilder.Entity>().ToTable("MyUserRoles"); modelBuilder.Entity>().ToTable("MyUserTokens"); } }
最佳回答
[SOLVE] Update ApplicationDbContext.cs. public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().ToTable("MyUsers"); // Rename other Identity tables modelBuilder.Entity().ToTable("MyRoles"); modelBuilder.Entity>().ToTable("MyRoleClaims"); modelBuilder.Entity>().ToTable("MyUserClaims"); modelBuilder.Entity>().ToTable("MyUserLogins"); modelBuilder.Entity>().ToTable("MyUserRoles"); modelBuilder.Entity>().ToTable("MyUserTokens"); // If you want to rename columns, e.g., rename Id to UserId // modelBuilder.Entity().Property(p => p.Id).HasColumnName("UserId"); } } Open Package Manage Console and run these 2 command to Update tables in Database Add-Migration RenameIdentityTables Update-Database If the tables still not change to New tables, search and change all old to new tables in ApplicationDbContextModelSnapshot.cs
问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签