1

Using this code for authentification:

HttpContext.Current.User=new GenericPrincipal
  (new GenericIdentity(user.UserName), roles);
FormsAuthentication.SetAuthCookie(user.UserName,false);

Problem is - on next request, HttpContext.Current.User.IsAuthenticated is true, but HttpContext.Current.User.IsInRole("admin") is false.

There are a lot of info on google but somehow nothing helps as usual.

Tried to add this to my web.config:

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

I do not want to use membership provider.

Any tips?

Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195
  • What kind of role provider do you use? – samy Oct 04 '10 at 11:47
  • *blind rabbit mode ON* sorry, i'm having a hard afternoon here :d Reflector says you're doing it right... perhaps you should double check what's in your roles string array – samy Oct 04 '10 at 11:57

2 Answers2

1

I think you might be trying to use the wrong kind of Identity if you're using forms authentication. You might be better off using FormsIdentity.

Article on Best Practices for Forms Authentication (might be outdated)

Joseph
  • 25,330
  • 8
  • 76
  • 125
0

Look like the IsInRole method is on the wrong interface. Try

HttpContext.Current.User.IsInRole("admin")
samy
  • 14,832
  • 2
  • 54
  • 82
  • Nah, that was just a typo. Didn't double check and wrote example as I remembered it. It's not solution. HttpContext.Current.User.Identity.IsInRole doesn't even compile. – Arnis Lapsa Oct 04 '10 at 12:03