適用 .NET Core v3 1.打開SqlServer, 並在 DB run 以下這一個 script https://gist.github.com/akatakritos/96b0c3136f8498246fa810d393927f04 2.在 Models folder 裡面加入 ApplicationUser 和 ApplicationRole class 3.打開自己的 DBContext, 並且把繼承後面的 DBContext 改成 IdentityDbContext<ApplicationUser, ApplicationRole, string> , 並且在同一個 DBContext 檔案裡面, 下面的 method 是 OnModelCreating() , 在裡面加入 base.OnModelCreating(modelBuilder); 4.去 Startup.cs 的 ConfigureServices register 這一個 ApplicationUser 跟 ApplicationRole 5.去 _LoginPartial.cshtml inject ApplicationUser 6.最後執行這一段 script INSERT INTO AspNetRoles (Id, Name, NormalizedName) Values ('1', 'Administrator', 'Administrator'); INSERT INTO AspNetRoles (Id, Name, NormalizedName) Values ('2', 'Customer', 'Customer'); Insert INTO AspNetUserRoles (RoleId, UserId) (Select '1', Id from AspNetUsers);
留言
張貼留言