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.
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
2 Posts
Roles.IsUserInRole doesn't work while User.IsInRole does
Mar 18, 2020 03:11 PM|arixmf|LINK
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
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?
Participant
1320 Points
491 Posts
Re: Roles.IsUserInRole doesn't work while User.IsInRole does
Mar 19, 2020 07:11 AM|jiadongm|LINK
Hi arixmf,
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
None
0 Points
2 Posts
Re: Roles.IsUserInRole doesn't work while User.IsInRole does
Mar 20, 2020 01:32 PM|arixmf|LINK
We're using ASP.NET Identity.
Yes, when user users use Roles.IsUserInRole, everything is working fine, even users with exactly the same roles.