I'm having trouble getting the Authorize
attribute to work with roles. Here's how I decorated my controller:
[Authorize(Roles = "admin")] public ActionResult Index() { ... }
and I register the user:
string roles = "admin"; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, username, DateTime.Now, DateTime.Now.AddMinutes(30), false, roles ); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); HttpContext.Current.Response.Cookies.Add(cookie);
But my user is still denied access. Where am I mistaken?
source share