question

YorkBush-0795 avatar image
0 Votes"
YorkBush-0795 asked RenaNi-MSFT edited

UserManager.RemoveFromRolesAsync and UserManager.IsInRoleAsyn return user not in role

I have a small project generated using vscode and dot net 7 core focused on Identity operations.

  • dotnet core project under parallels windows 11 on an M1 max macbook

  • Docker container running azure edge with a database simply for testing identity

  • program.cs setup

  • migrations generated and applied to the database

  • Identity tables are created and present in the database

  • able to create a User in the the Users table

  • able to create a Role in the Roles table

  • able to associate the user with the roles and a relationship row appears in the UserRoles table

  • able to retrieve the user and user rolls with

        var user = await _userManager.FindByEmailAsync(email);
                
          var roles = await _userManager.GetRolesAsync(user);
    

  • unable to use

       var role_result = await _userManager.IsInRoleAsync(user, roleName);
         var result = await _userManager.RemoveFromRolesAsync(user, roleName);
    
         both of these api calls return false with an error "user not in role".   I have done a bit of sanity checking and can't seem to see anything obvious.  
    

  • Are there any tools/utilities I can use out of the box to test the basic setup for Identity.

  • Suggestions on gathering additional debug information ?


Thank you!


dotnet-aspnet-core-generaldotnet-standardmicrosoft-identity-managerdotnet-entity-framework
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @YorkBush-0795, how do you add the role to user? How do you configure the Identity in Program.cs? More code would be helpful. Thank you.

0 Votes 0 ·

0 Answers