0

in my project, I have a user with 2 position, so, I have added a user with 2 roles in AspNetUserRoles table in my database,

so, for example, my user with this username : "[email protected]" has 2 roles: "accountant" and "ExecutiveExpert"

but when I call User.IsInRole("ExecutiveExpert") function, it just check the first role : accountant, not all the roles (accountant and ExecutiveExpert) and it returns false,

how can I change the asp.net Identity to check all the user roles? is it possible generally ?

these are my tables :

[AspNetUsers]:ID: c35721e2-05ef-4c32-8915-b4ad117c5a98 [AspNetRoles]: Id Name 743f5c09-2b94-4da6-ab1c-9c9a6c9373b7 accountant 845efdf6-ab07-475c-9eb1-b14365b1a54c ExecutiveExpert [AspNetUserRoles]: userID RoleID c35721e2-05ef-4c32-8915-b4ad117c5a98 743f5c09-2b94-4da6-ab1c-9c9a6c9373b7 c35721e2-05ef-4c32-8915-b4ad117c5a98 845efdf6-ab07-475c-9eb1-b14365b1a54c 
8
  • I don't get what you're saying. User.IsInRole will just give you a boolean. If it has the specified role, you'll get true, otherwise false. Commented Jun 1, 2017 at 18:49
  • You need to pass a string to IsInRole. See the docs Commented Jun 1, 2017 at 18:50
  • @mason: I just edit my question, would you please read it again? thank you. Commented Jun 1, 2017 at 18:55
  • I still don't get what you're asking. IsInRole only checks one role at a time. If you want to check two, you'd do something like bool hasBothRoles = User.IsInRole("Role1") && User.IsInRole ("Role2"); If IsInrole is reporting the wrong thing for a single role, then you've got a completely different issue. Commented Jun 1, 2017 at 18:58
  • @mason: my problem is that this user does not have ExecutiveExpert role, but I added this role in database for him,: in AspNetUserRoles table , it has accountant and ExecutiveExpert role Commented Jun 1, 2017 at 19:04

1 Answer 1

2

In this case, the security stamp is updated. You need specifically renew/reset the security stamp

UserManager.UpdateSecurityStampAsync(userId); 

This will help to fix your issue.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.