sthashakun
sthashakun

Reputation: 50

ASP.NET Core Identity 3.1: UserManager.RemoveFromRoleAsync always returns UserNotInRole

Im able to create roles using role manager and add user to a role using UserManager.AddToRoleAsync But when using method UserManager.RemoveFromRoleAsync(User, Role), im always getting error saying UserNotInRole

enter image description here

Any idea what is causing this weird behaviour? Im using Identity.Core, Version=3.1.3.0

Updated the code snippet

My AspNetUserole Table

enter image description here

Refer to below image, only methods IsInRoleAsync & RemoveFromRoleAsync get fails, other methods are getting results.

enter image description here

Upvotes: 1

Views: 801

Answers (1)

Mukta Dhungana
Mukta Dhungana

Reputation: 46

Looks like your keys for the identity UserRole table is configured wrongly. Can post the code snippet where you have modified the IdentityUserRole table?

It should be like following configuration

builder.Entity<IdentityUserRole<int>>().ToTable("Rmit.UserRole").HasKey(k => new {  k.UserId,k.RoleId });

Upvotes: 3

Related Questions