zoukankan      html  css  js  c++  java
  • 把多条数据序列化存储在cookie并取出

     1 namespace shendeng.lottery.helper
     2 {
     3     public class ControllerHelper
     4     {
     5         /// <summary>
     6         /// 取出公告
     7         /// </summary>
     8         /// <returns></returns>
     9         public static List<New> GetNewList()
    10         {
    11             List<New> list = null;
    12             System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
    13             //如果cookie里有值就直接取
    14             if (System.Web.HttpContext.Current.Request.Cookies["news"] != null)
    15             {
    16                 string strNews = System.Web.HttpContext.Current.Request.Cookies["news"].Value;
    17                 if (!string.IsNullOrEmpty(strNews))
    18                 {
    19                     list = jss.Deserialize<List<New>>(strNews);
    20                 }
    21             }
    22             else
    23             {
    24                 //lotteryDataContex datas = new DatabaseFactory().Get();
    25                 //公告类型
    26                 Guid newtypeId = Guid.Parse("6029379D-06D0-42E8-8DE6-872B4A621B65");
    27                 list = new NewRepository(new DatabaseFactory()).GetTopManyOrderBy(n => n.NewTypeId == newtypeId && n.StartTime < DateTime.Now && n.EndTime > DateTime.Now && n.State != 9 && n.Enabled == true, n => n.CreateTime, 5, true).ToList();
    28                 //序列化存入cookie
    29                 string serList = jss.Serialize(list);
    30                 HttpCookie hc = new HttpCookie("news", serList);
    31                 hc.Expires = DateTime.Now.AddHours(2);
    32                 System.Web.HttpContext.Current.Response.Cookies.Add(hc);
    33             }
    34             return list;
    35         }
    36 
    37 
    38 
    39     }
    40 }
  • 相关阅读:
    webim-界面细节调整
    使用PHP得到所有的HTTP请求头_还有应答头
    Bootstrap学习的点点滴滴
    asterisk中eyebeam与移动的IMS帐号对接
    总结Ajax跨域调用问题
    Spring【基础】-注解-转载
    Spring-【高阶】注解-转载
    让你的IDEA倍爽
    IDEA的git密码修改
    Idea设置签名
  • 原文地址:https://www.cnblogs.com/LYunF/p/2946081.html
Copyright © 2011-2022 走看看