In the debugger, if I dig into the User object, I can see the current member's UserData property, ((System.Web.Security.FormsIdentity)(User.Identity)).Ticket.UserData
, has "admin" in it.
User.Identity.IsAuthenticated
works, User.IsInRole("admin")
returns false.
If "admin" is in the UserData property, shouldn't User.IsInRole("admin") return true?
Update
I set the FormsAuthenticationTicket like so:
public static string CreateEncryptedTicket(string username, string roles, DateTime expireAt, bool isPersistent = true) {
var ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, expireAt, isPersistent, roles, FormsAuthentication.FormsCookiePath);
return FormsAuthentication.Encrypt(ticket);
}
then (where roles is a comma separated list of roles the member is in):
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, MemberService.CreateEncryptedTicket(member.Id, roles, expireDate));
HttpContext.Response.Cookies.Add(cookie);