日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)其它知識 → 編程實(shí)現(xiàn)cookies瀏覽歷史記錄功能

      編程實(shí)現(xiàn)cookies瀏覽歷史記錄功能

      前往專題相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時(shí)間:2011/1/4 22:34:39字體大。A-A+

      作者:佚名點(diǎn)擊:240次評論:0次標(biāo)簽: cookies

      cookies清除V4.1.8.8 綠色漢化版
      • 類型:卸載刪除大。1.3M語言:中文 評分:8.3
      • 標(biāo)簽:
      立即下載
       1.創(chuàng)建歷史記錄的實(shí)體類
      public class LastProducts
      {
      private int _productid;
      private int _categoryid;
      private string _imgsrc;
      private string _productname;

      public LastProducts(int id,int typeid,string imgsrc,string restorename)
      {
      _productid = id;
      _categoryid = typeid;
      _imgsrc = imgsrc;
      _productname = restorename;
      }

      public int ProductId
      {
      get { return _productid; }
      }

      public int CategoryId
      {
      get { return _categoryid; }
      }

      public string ImgSrc
      {
      get { return _imgsrc; }
      }

      public string ProductName
      {
      get { return _productname; }
      }
      }


      2.定義存儲cookies的方法
      public void HistoryRestore(string cookieName,int objectID)
      {
      HttpRequest Request = HttpContext.Current.Request;
      HttpResponse Response = HttpContext.Current.Response;

      if (Request.Cookies[cookieName] != null)
      {
      HttpCookie tempCurBuyerList = Request.Cookies[cookieName];
      string tempstr = tempCurBuyerList.Value;
      if (tempstr.IndexOf(",") > 0)
      {
      string[] sArray = tempstr.Split(',');
      bool hasthis = false;

      foreach (string s in sArray)
      {
      if (s == objectID.ToString())
      {
      hasthis = true;
      break;
      }
      else
      {
      hasthis = false;
      }
      }

      if (!hasthis) //如果沒有ID,則加入
      {
      if (sArray.Length > 3) //3為存儲瀏覽記錄數(shù)的數(shù)量,實(shí)際數(shù)量為7
      {
      // 超過數(shù)量,去掉最先入隊(duì)的元素
      tempstr = tempstr.Substring(0, tempstr.LastIndexOf(","));
      }
      // 隊(duì)列
      tempstr = objectID.ToString() + "," + tempstr;
      }
      }
      else
      {
      //tempstr += "," + objectID.ToString();
      if (tempstr != objectID.ToString())
      {
      tempstr = objectID.ToString() + "," + tempstr;
      }
      }
      tempCurBuyerList.Value = tempstr;
      tempCurBuyerList.Expires = DateTime.Now.AddDays(1);
      Response.Cookies.Add(tempCurBuyerList);
      //或者 Response.Cookies[cookieName].Value = tempstr;
      }
      else
      {
      HttpCookie addToCookies = new HttpCookie(cookieName);
      addToCookies.Value = objectID.ToString();
      addToCookies.Expires = DateTime.Now.AddDays(1);
      Response.Cookies.Add(addToCookies);
      }
      }


      3.讀取cookies存儲數(shù)據(jù)
      public List<LastProducts> GetLastProducts()
      {
      HttpRequest Request = HttpContext.Current.Request;

      List<LastProducts> list = null;

      if (Request.Cookies["restoreid"] != null)
      {
      HttpCookie tempCurBuyerList = Request.Cookies["restoreid"];

      string[] strArr = tempCurBuyerList.Value.Split(',');
      list = new List<LastProducts>();

      foreach (string s in strArr)
      {
      ShopProduct model = dal.GetProById(int.Parse(s)); //商品的實(shí)體類
      if (model != null)
      {
      list.Add(new Model.Shop.LastProducts(model.ProductID, model.CategoryID, model.ImageHref, model.Name));
      }
      }
      }

      return list;
      }


      4.在用戶瀏覽某產(chǎn)品時(shí)記錄到cookies中:

      HistoryRestore("restoreid",productId);


      5.數(shù)據(jù)源的綁定
        Repeater1.DataSource = GetLastProducts();
      Repeater1.DataBind();

        相關(guān)評論

        閱讀本文后您有什么感想? 已有人給出評價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)