Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void createCookie(string username, int customerID, bool persist)
- {
- HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, persist);
- cookie.Expires = DateTime.Now.AddHours(12);
- var ticket = FormsAuthentication.Decrypt(cookie.Value);
- var userData = customerID.ToString();
- var newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, userData);
- cookie.Value = FormsAuthentication.Encrypt(newTicket);
- Response.Cookies.Add(cookie);
- }
- protected void Login1_LoggedIn(object sender, EventArgs e)
- {
- //... unimportant code left out
- //Update the users ticket with custom userInfo object
- string userData = userInfo.Id.ToString("N");
- HttpCookie cookie = Response.Cookies.Get(FormsAuthentication.FormsCookieName);
- FormsAuthenticationTicket oldTicket = FormsAuthentication.Decrypt(cookie.Value);
- FormsAuthenticationTicket newTicket =
- new FormsAuthenticationTicket(
- oldTicket.Version,
- oldTicket.Name,
- oldTicket.IssueDate,
- oldTicket.Expiration,
- oldTicket.IsPersistent,
- userData,
- oldTicket.CookiePath);
- cookie.Value = FormsAuthentication.Encrypt(newTicket);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement