Reputation: 1064
I know this question is asked many times. I tried all solutions but not getting it worked. I a using MVC4 and using forms authentication. I am not using membership but want to store roles in Forms Authentication. I am using below code to achieve my goal.
FormsAuthentication.SetAuthCookie(result.ID.ToString(), false);
GenericPrincipal gp = new GenericPrincipal(HttpContext.User.Identity, new string[] { "admin" });
HttpContext.User = gp;
I am getting username and IsAuthenticated successfully using User.Identity.Name
and User.Identity.IsAuthenticated
but when I am trying to check role using code var role = User.IsInRole("admin");
it is returning false.
Please help.
Upvotes: 0
Views: 286