public static string GenerateExpiredCookieValue() { var expiration = DateTime.UtcNow.AddDays(-1); string compositeToken = Guid.Empty.ToString(); string compositeEwName = ""; string compositeEwRole = ""; string compositeExpiresOn = expiration.Ticks.ToString(); string composite = string.Format("{0}|{1}|{2}|{3}", compositeToken, compositeEwName, compositeEwRole, compositeExpiresOn); return(TextEncrytion.EncryptString(composite, secretKey)); }
private static void RefreshCookie(CookieInfo info) { var compositeToken = Guid.NewGuid().ToString(); var compositeEwName = info.EarthwatcherName; var compositeEwRole = string.Join(",", info.Roles); var expiresOn = info.KeepLogged ? DateTime.UtcNow.AddDays(15) : DateTime.UtcNow.AddMinutes(30); var compositeExpiresOn = expiresOn.ToString(); string composite = string.Format("{0}|{1}|{2}|{3}|{4}", compositeToken, compositeEwName, compositeEwRole, compositeExpiresOn, info.KeepLogged); string strToken = TextEncrytion.EncryptString(composite, Session.secretKey); HttpCookie cookie = new HttpCookie(Session.TOKENKEY); cookie.Value = strToken; cookie.HttpOnly = false; cookie.Expires = expiresOn; System.Web.HttpContext.Current.Response.Cookies.Set(cookie); }
public static string GenerateCookie(Earthwatcher ew, bool keeplogued = true) { string compositeToken = Guid.NewGuid().ToString(); string compositeEwName = ew.Name; string compositeEwRole = string.Join(",", ew.GetRoles()); var expiresOn = keeplogued ? DateTime.UtcNow.AddDays(15) : DateTime.UtcNow.AddMinutes(30); var compositeExpiresOn = expiresOn.ToString(); string composite = string.Format("{0}|{1}|{2}|{3}|{4}", compositeToken, compositeEwName, compositeEwRole, compositeExpiresOn, keeplogued); string strToken = TextEncrytion.EncryptString(composite, Session.secretKey); HttpCookie cookie = new HttpCookie(Session.TOKENKEY); cookie.Value = strToken; cookie.Expires = expiresOn; cookie.HttpOnly = false; System.Web.HttpContext.Current.Response.Cookies.Add(cookie); return(strToken); }