title: Claims Based Forms Authentication Roles
body: <p>I'm trying to authenticate a user using forms authentication in MVC 4 (I'm using RavenDB so I can't use the standard membership providers).  Then later I'm using the <code>User.IsInRole()</code> method or <code>AuthorizeAttribute</code> to verify the user is in a staff role.</p>
  
  <p>Here's where I set the ticket on successful authentication (at the moment in <code>UserController.cs</code>):</p>
  
  <pre><code>FormsAuthenticationTicket ticket =
      new FormsAuthenticationTicket(
          1,
          model.Email,
          DateTime.Now,
          DateTime.Now.AddDays(1),
          false,
          model.Email);
  
  string hashedTicket = FormsAuthentication.Encrypt(ticket);
  
  HttpCookie cookie =
      new HttpCookie(
          FormsAuthentication.FormsCookieName,
          hashedTicket);
  
  HttpContext.Response.Cookies.Add(cookie);
  </code></pre>
  
  <p>Here's where I check the ticket for each request (<code>Global.asax</code>):</p>
  
  <pre><code>protected void Application_AuthenticateRequest(object sender, EventArgs e)
  {
      var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
  
      if (authCookie != null)
      {
          var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
          var user = this.UserService.GetUserByEmail(authTicket.Name);
  
          var identity = new GenericIdentity(authTicket.Name, "Forms");
  
          var principal = new GenericPrincipal(identity, user.Roles);
  
          HttpContext.Current.User = principal;
      }
  }
  </code></pre>
  
  <p>If I then put a debug point on one of my action methods (CalendarController.cs), I get <code>isStaff</code> equals <code>false</code>:</p>
  
  <pre><code>public ActionResult Index()
  {
      var user = HttpContext.User;
  
      bool isStaff = user.IsInRole(Role.Staff);
  
      return View();
  }
  </code></pre>
  
  <p>Just for completion (Roles.cs, just a temporary class to test things):</p>
  
  <pre><code>public static class Role
  {
      public static string Staff
      {
          get { return "Staff"; }
      }
  
      public static string Manager
      {
          get { return "Manager"; }
      }
  }
  </code></pre>
  
  <p>Can anyone help give me a point as to what I might be missing?  It looks as though the roles I set are disappearing by the time I get to the action method.</p>