コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public static void AddCookie(this HttpContextBase httpContextBase, string cookieName, string value)
 {
     httpContextBase.AddCookie(cookieName, value, DateTime.Now.AddDays(30));
 }
コード例 #4
0
 public void Store <T>(string key, T value) where T : class
 {
     _httpContextBase.AddCookie(key, CookieExtention.SerializeToBase64EncodedString(value));
 }