// Read the cookie HttpCookie cookie = FormsAuthentication.GetAuthCookie(Session[Constants.UserName].ToString(), true); // Decrypt the cookie to get ticket FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value); // Create new ticket from old and update roles FormsAuthenticationTicket newticket = new FormsAuthenticationTicket
(ticket.Version, // Ticket version ticket.Name, // Username associated with ticket ticket.IssueDate, // Date/time issued ticket.Expiration, // Date/time to expire
false, //"true" for a persistent user cookie
DropDownListRole.SelectedItem.Text, //User-data, in this case the roles from a dropdown
ticket.CookiePath);
// Encrypt the ticket and store it in
the cookie cookie.Value = FormsAuthentication.Encrypt(newticket);
// Set the cookie's expiration time to
the tickets expiration time if (ticket.IsPersistent) cookie.Expires = newticket.Expiration;
// Add the cookie to the list for outgoing response
HttpContext.Current.Response.Cookies.Add(cookie); |