I am using the existing table to login and logout from the application. I want to use asp.net User identity framework to this project. So I want to include my existing user table as Identity User. Please can you guide me with simple steps how to add existing
user table as user identity table.
I am using two model
User.cs
[Key]
UserId int {get;set;}
UserName string {get;set;} // using for login
Password string {get;set}
FirstName string {get;set;}
LastName string {get;set;} EmailAddress string {get;set}
RoleId int{get;set;}
UserRole UserRole {get;set;}
UserRole.cs
RoleId int {get;set;}
RoleName string {get;set;)
I changed the code in dbContext class with required namespace.
public class MyContext : IdentityDbContext<User, UserRole, int>
{
//public GoContext()
//{
//}
public MyContext(DbContextOptions<MyContext> options)
: base(options)
{
}
}
But after that the following error is being showed
User,UserRole cannot be used as type parameter in the generic type or method 'IdentityDbContext<Tuser,TRole,Tkey>. There is no implicit reference conversion from User, UserRol into Microsoft.AspNetCore.Identity.IdentityUser and Identityrole.
Please can you help to fix this issue to go to next step, it would be very appreciated
Member
400 Points
1295 Posts
How can I customize the Identity user table in my existing project
Oct 29, 2020 10:28 AM|polachan|LINK
Hi
I am using the existing table to login and logout from the application. I want to use asp.net User identity framework to this project. So I want to include my existing user table as Identity User. Please can you guide me with simple steps how to add existing user table as user identity table.
I am using two model
I changed the code in dbContext class with required namespace.
But after that the following error is being showed
User,UserRole cannot be used as type parameter in the generic type or method 'IdentityDbContext<Tuser,TRole,Tkey>. There is no implicit reference conversion from User, UserRol into Microsoft.AspNetCore.Identity.IdentityUser and Identityrole.
Please can you help to fix this issue to go to next step, it would be very appreciated
All-Star
52291 Points
23326 Posts
Re: How can I customize the Identity user table in my existing project
Oct 29, 2020 10:59 AM|mgebhard|LINK
Implementing a different Identity schema is not a simple process as you assume. This requires a solid understanding of the Identity API.
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/customize-identity-model?view=aspnetcore-3.1
I recommend moving the existing data into the Identity tables. The password is a little tricky. You'll write code to hash the passwords.