title: Unable to retrieve UserData on Forms authentication ticket
body: <p>I am trying to get some custom field values from my authentication ticket by running the following code in my controller - </p>
  
  <pre><code>[HttpPost]
      public ActionResult Add(AddCustomerModel customer)
      {
          customer.DateCreated = DateTime.Now;
          customer.CreatedBy = ((CustomPrincipal)(HttpContext.User)).Id;
          customer.LastUpdated = DateTime.Now;
          customer.LastUpdateBy = ((CustomPrincipal)(HttpContext.User)).Id;
  
          if (ModelState.IsValid)
          {
              _customerService.AddCustomer(customer);
  
              return RedirectToAction("Index");
          }
  
          return View(customer);
      }
  </code></pre>
  
  <p>When I try and set the CreatedBy field for the new customer, I get the following error - </p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Security.Principal.GenericPrincipal' to type 'GMS.Core.Models.CustomPrincipal'.</p>
  </blockquote>
  
  <p>My userData field within the FormsAuthenticationTicket is set with a JSON string which contains two fields - Id and FullName.</p>
  
  <p>Here is my login method on the controller - </p>
  
  <pre><code>    [HttpPost]
      [AllowAnonymous]
      public ActionResult Login(LoginModel model, string returnUrl)
      {
          if (Membership.ValidateUser(model.EmailAddress, model.Password))
          {
              LoginModel user = _userService.GetUserByEmail(model.EmailAddress);
  
              CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();
              serializeModel.Id = user.ID;
              serializeModel.FullName = user.EmailAddress;
              //serializeModel.MergedRights = user.MergedRights;
  
              JavaScriptSerializer serializer = new JavaScriptSerializer();
  
              string userData = serializer.Serialize(serializeModel);
  
              FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
               1,
               user.EmailAddress,
               DateTime.Now,
               DateTime.Now.AddHours(12),
               false,
               userData);
  
              string encTicket = FormsAuthentication.Encrypt(authTicket);
              HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
              Response.Cookies.Add(faCookie);
  
              return RedirectToAction("Index", "Dashboard");
          }
  
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>Any ideas where I am going wrong? </p>