Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void AddUserIDToAuthCookie(string userID)
- {
- //There is no way to directly set the userdata portion of a FormAuthenticationTicket
- //without re-writing the login portion of the Login control
- //
- //I find it easier to pull the cookie that the Login control inserted out
- //and create a new cookie with the userdata set
- HttpCookie authCookie = Response.Cookies[AUTH_COOKIE];
- if(authCookie == null)
- {
- return;
- }
- Response.Cookies.Remove(AUTH_COOKIE);
- FormsAuthenticationTicket oldTicket = FormsAuthentication.Decrypt(authCookie.Value);
- var newTicket =
- new FormsAuthenticationTicket(oldTicket.Version, oldTicket.Name, oldTicket.IssueDate, oldTicket.Expiration,
- oldTicket.IsPersistent, userID, oldTicket.CookiePath);
- authCookie.Value = FormsAuthentication.Encrypt(newTicket);
- Response.Cookies.Add(authCookie);
- }
- FormsAuthenticationTicket ticket = ((FormsIdentity) Page.User.Identity).Ticket;
- string id = ticket.UserData;
Add Comment
Please, Sign In to add comment