asp.net-identity-3

How to make EF-Core use a Guid instead of String for its ID/Primary key

廉价感情. 提交于 2019-11-27 18:50:15
When I look at the ASP.NET 3 Identity it uses a string and not a Guid for the unique primary key. In my Entity Framework code first Users' ApplicationUser class I inherit the Identity class public class ApplicationUser : IdentityUser { } which results in when I create my Entity Framework migrations a table aspnetusers getting created with a key type of nvarchar(450) instead of uniqueidentifier When I compare this to ASP.NET Identity 2 ENtity Framework project it created an ID field of uniqueidentifier and not nvarchar(450) I would imagine for database performance primary keys and foreign keys

How to make EF-Core use a Guid instead of String for its ID/Primary key

北战南征 提交于 2019-11-26 15:52:03
问题 When I look at the ASP.NET 3 Identity it uses a string and not a Guid for the unique primary key. In my Entity Framework code first Users' ApplicationUser class I inherit the Identity class public class ApplicationUser : IdentityUser { } which results in when I create my Entity Framework migrations a table aspnetusers getting created with a key type of nvarchar(450) instead of uniqueidentifier When I compare this to ASP.NET Identity 2 ENtity Framework project it created an ID field of

How to create roles in asp.net core and assign them to users

扶醉桌前 提交于 2019-11-26 09:17:02
问题 I am using asp.net core default web site template and authentication selected as individual user account. How can I create role and assign it to user so that I can use role in controller to filter the access. 回答1: I created a action in the account controller that call a function to create the roles and affect the admin role to a default user (You should probably remove the default user in production): private async Task createRolesandUsers() { bool x = await _roleManager.RoleExistsAsync(