public static bool CanUserVoteBasedOnCookies(this HttpContextBase httpContext, int postId, string sectionType) { string key = sectionType + "-" + postId; var value = httpContext.GetCookieValue(key); if (string.IsNullOrWhiteSpace(value)) { httpContext.AddCookie(key, key); return(true); } return(false); }
private void SaveSessionObjectDataToCookie(SessionData data, HttpContextBase context) { //for performance reason, save session object data to http context SaveSessionObjectDataToHttpContext(data, context); BinaryFormatter bin = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); bin.Serialize(stream, data); string dataString = Convert.ToBase64String(stream.ToArray()); stream.Close(); string sessionId = data.Username; string ticket = string.Format("{0}{1}", DateTime.Now.Ticks, Guid.NewGuid()); string chksum = CreateChecksum(dataString, ticket, sessionId); string cookieValue = string.Format("{0}*****{1}*****{2}", dataString, ticket, chksum); context.AddCookie(_sessionDataCookieName, cookieValue); }
public static void AddCookie(this HttpContextBase httpContextBase, string cookieName, string value) { httpContextBase.AddCookie(cookieName, value, DateTime.Now.AddDays(30)); }
public void Store <T>(string key, T value) where T : class { _httpContextBase.AddCookie(key, CookieExtention.SerializeToBase64EncodedString(value)); }