web.config

<system.web>
<roleManager enabled="true"/>
</system.web>

in asp.net mvc 5, i'm trying to detect the role of the current user so i can redirect him to a page specific to it's role but

in my controller

if (Roles.IsUserInRole(User.Identity.GetUserName(), "superadmin")

or

if (Roles.IsUserInRole(User.Identity.Name, "superadmin")

the both are not true, i'm sure that i'm logged bec User.Identity.GetUserName() is displaying my login

Trying to debug, i found that Roles.GetRolesForUser() is empty, i've checked online resources but still no solution

Further debugging shows that Roles.GetAllRoles() is also empty, but my AspNetRoles table has 5 records.

I've looked at AspNetUserRoles and i found my current User id assigned to specific role id

Related posts

Recent Viewed