locked
Roles.IsUserInRole doesn't work while User.IsInRole does RRS feed

  • Question

  • User1041678997 posted

    I have an ASP.NET MVC application and I have a weird problems going on.

    For a specific set of production users, `Roles.IsUserInRole` (which is used throughout my codebase) doesn't work (It returns false for a permission that the user is supposed to have)

    When I replace it with `User.IsInRole` it works as expected.

    From what I see in the reference source
    As long as the user exists in the http context, `Roles.IsUserInRole` calls internally to `User.IsInRole`.

    I've added some debug logs to my application and I've verified that

    • The user exists in the http context
    • The user object in the context is of type `RolePrincipal`
    • The `ProviderName` in the user object equals to the `Name` field in my roles provider
    • The roles that are returned from my roles provider are correct

    I'm out of options.
    According to all the logging and source code inspection that I did, there shouldn't be any problem with using `Roles.IsUserInRole`

    The weird thing is that it's happening only in our production environment and only for specific users.

    What could it be?

    Wednesday, March 18, 2020 3:11 PM

All replies

  • User-17257777 posted

    Hi arixmf,

    The weird thing is that it's happening only in our production environment and only for specific users.

    Are you using the ASP.NET Identity or custome authentication? And what's the specific users' role, is it ok when other role users use Roles.IsUserInRole?

    Best Regards,

    Jiadong Meng

    Thursday, March 19, 2020 7:11 AM
  • User1041678997 posted

    We're using ASP.NET Identity.

    Yes, when user users use Roles.IsUserInRole, everything is working fine, even users with exactly the same roles.

    Friday, March 20, 2020 1:32 PM