MrMistreater

Create authentication cookie

Apr 24th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. public static HttpCookie BuildCookie(int userprofileId)
  2. {
  3.     FormsAuthentication.Initialize();
  4.  
  5.     FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
  6.         1,
  7.         userprofileId.ToString(CultureInfo.InvariantCulture),
  8.         DateTime.Now,
  9.         DateTime.Now.AddMinutes(30),
  10.         false,
  11.         UserprofileRole.GetStringByUserprofile(userprofileId),
  12.         FormsAuthentication.FormsCookiePath);
  13.  
  14.     string hashedTicket = FormsAuthentication.Encrypt(ticket);
  15.     HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashedTicket);
  16.     return cookie;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment