Issue with trying to use multiple identities .net core 5.0

BBK_Developer 26 Reputation points
2021-12-22T06:03:33.043+00:00

Hi everyone,

I am new to asp.net core and i started working on asp.net from version 5.0 core. I have switched to asp.net from laravel php framework. This was my brief introduction. I have been working on asp.net and using database first approach i built dbcontext and implemented my whole system in asp.net but in start i wanted to use identity scaffolding and use all commands that added a new identitydbcontext. So i have now two dbcontext one is asp.net core default with only identity and other is my database from db first approach.

I have implemented the default identity system by using

services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
                .AddRoles<IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>();

But after this i wanted to authenticate users against a custom model tblemployee with fields i.e phone and scale. But when i try to add this by using a method that I found here Asp.net core 2.0 multiple identity .

My code to do that is

services.AddIdentityCore<TblEmployee>().AddEntityFrameworkStores<DbBzuCCContext>().AddDefaultTokenProviders();

But the code is not working it says that extend from IdentityUser but i can't use identityuser fields in my model. I just want to use my 2 fields to work as additional identity provider. Is there any way in middle ware to change default route for different identity and all my previous controllers to be used from default identity but new one with other identity.

Any help will be highly appreciated.

Regards,

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,238 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,312 questions
{count} votes

Accepted answer
  1. AgaveJoe 26,166 Reputation points
    2022-01-07T18:43:07.01+00:00

    The authentication cookie middleware handles authorization in .NET Core. Simply create an authentication cookie and the roles/claims needed for authorization when the user successfully authenticates on the other URL.

    Use cookie authentication without ASP.NET Core Identity
    Role-based authorization in ASP.NET Core
    Claims-based authorization in ASP.NET Core


0 additional answers

Sort by: Most helpful