Skip to content

Instantly share code, notes, and snippets.

@Dynyx
Created June 4, 2012 13:33
Show Gist options
  • Save Dynyx/2868407 to your computer and use it in GitHub Desktop.
Save Dynyx/2868407 to your computer and use it in GitHub Desktop.
Create authentication cookie
public static HttpCookie BuildCookie(int userprofileId)
{
FormsAuthentication.Initialize();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
userprofileId.ToString(CultureInfo.InvariantCulture),
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
UserprofileRole.GetStringByUserprofile(userprofileId),
FormsAuthentication.FormsCookiePath);
string hashedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashedTicket);
return cookie;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment