1: private static HttpCookie GetAuthCookie(string userName, bool createPersistentCookie, string strCookiePath, bool hexEncodedTicket)
2: {
3: FormsAuthentication.Initialize();
4: if (userName == null)
5: userName = string.Empty;
6: if (strCookiePath == null || strCookiePath.Length < 1)
7: strCookiePath = FormsAuthentication.FormsCookiePath;
8: DateTime utcNow = DateTime.UtcNow;
9: DateTime expirationUtc = utcNow.AddMinutes((double) FormsAuthentication._Timeout);
10: FormsAuthenticationTicket ticket = FormsAuthenticationTicket.FromUtc(2, userName, utcNow, expirationUtc, createPersistentCookie, string.Empty, strCookiePath);
11: string str = FormsAuthentication.Encrypt(ticket, hexEncodedTicket);
12: if (str == null || str.Length < 1)
13: throw new HttpException(System.Web.SR.GetString("Unable_to_encrypt_cookie_ticket"));
14: HttpCookie httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, str);
15: httpCookie.HttpOnly = true;
16: httpCookie.Path = strCookiePath;
17: httpCookie.Secure = FormsAuthentication._RequireSSL;
18: if (FormsAuthentication._CookieDomain != null)
19: httpCookie.Domain = FormsAuthentication._CookieDomain;
20: if (ticket.IsPersistent)
21: httpCookie.Expires = ticket.Expiration;
22: return httpCookie;
23: }