This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 14th, 2012  |  syntax: None  |  size: 1.32 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. private void createCookie(string username, int customerID, bool persist)
  2. {
  3.     HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, persist);
  4.     cookie.Expires = DateTime.Now.AddHours(12);
  5.     var ticket = FormsAuthentication.Decrypt(cookie.Value);
  6.     var userData = customerID.ToString();
  7.     var newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userData);
  8.     cookie.Value = FormsAuthentication.Encrypt(newTicket);
  9.     Response.Cookies.Add(cookie);
  10. }
  11.        
  12. protected void Login1_LoggedIn(object sender, EventArgs e)
  13.     {
  14.         //... unimportant code left out
  15.  
  16.         //Update the users ticket with custom userInfo object
  17.         string userData = userInfo.Id.ToString("N");
  18.         HttpCookie cookie = Response.Cookies.Get(FormsAuthentication.FormsCookieName);
  19.         FormsAuthenticationTicket oldTicket = FormsAuthentication.Decrypt(cookie.Value);
  20.         FormsAuthenticationTicket newTicket =
  21.             new FormsAuthenticationTicket(
  22.                 oldTicket.Version,
  23.                 oldTicket.Name,
  24.                 oldTicket.IssueDate,
  25.                 oldTicket.Expiration,
  26.                 oldTicket.IsPersistent,
  27.                 userData,
  28.                 oldTicket.CookiePath);
  29.         cookie.Value = FormsAuthentication.Encrypt(newTicket);
  30.  }
clone this paste RAW Paste Data