In my AccountController, I have code like this:
ControllerContext.HttpContext.User = new MyAppUserPrincipal(user);
When I step through this in the debugger I can see that ControllerContext.HttpContext.User.IsInRole("Admin") is true.
Next, I have a HomeController protected by a custom attribute:
[AuthorizeMyApp(Roles = "Admin")]
In the definition of the attribute, I have this:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var principal = filterContext.HttpContext.User ;
if (! principal.IsInRole(_roles) )
etc.
Here's what's weird, after logging in and trying to go to Home:
principal.Identity.Name has the expected name, and IsAuthenticate is true; however a) principal.IsInRole("Admin") is false b) (principal As MyAppUserPrincipal) is null
Am I doing something wrong here? (using MVC2)