0

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.

Rahul Jha
  • 874
  • 1
  • 11
  • 28
  • Where are you storing the roles? – David Tansey Oct 04 '15 at 19:43
  • @DavidTansey I don't know much about roles. I checked on google about how to use role without using membership and got above code. Everything is working fine except role. If you will see, I have mentioned admin role in GenericPrinciple. – Rahul Jha Oct 05 '15 at 06:37

0 Answers0