• <td id="ae6ms"><li id="ae6ms"></li></td>
  • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
  • <table id="ae6ms"></table>
  • <td id="ae6ms"></td>
    <td id="ae6ms"></td>
  • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
  • <td id="ae6ms"></td>
  • <table id="ae6ms"><li id="ae6ms"></li></table>
  • <table id="ae6ms"></table>
    西西軟件園多重安全檢測下載網站、值得信賴的軟件下載站!
    軟件
    軟件
    文章
    搜索

    首頁編程開發其它知識 → 編程實現cookies瀏覽歷史記錄功能

    編程實現cookies瀏覽歷史記錄功能

    前往專題相關軟件相關文章發表評論 來源:本站整理時間:2011/1/4 22:34:39字體大?。?em class="fontsize">A-A+

    作者:佚名點擊:240次評論:0次標簽: cookies

    cookies清除V4.1.8.8 綠色漢化版
    • 類型:卸載刪除大?。?i>1.3M語言:中文 評分:8.3
    • 標簽:
    立即下載
     1.創建歷史記錄的實體類
    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為存儲瀏覽記錄數的數量,實際數量為7
    {
    // 超過數量,去掉最先入隊的元素
    tempstr = tempstr.Substring(0, tempstr.LastIndexOf(","));
    }
    // 隊列
    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存儲數據
    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)); //商品的實體類
    if (model != null)
    {
    list.Add(new Model.Shop.LastProducts(model.ProductID, model.CategoryID, model.ImageHref, model.Name));
    }
    }
    }

    return list;
    }


    4.在用戶瀏覽某產品時記錄到cookies中:

    HistoryRestore("restoreid",productId);


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

      相關評論

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

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

      熱門評論

      最新評論

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

      昵稱:
      表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
      字數: 0/500 (您的評論需要經過審核才能顯示)
      女人让男人桶30分钟免费视频,女人张开腿让男人桶个爽,一进一出又大又粗爽视频
    • <td id="ae6ms"><li id="ae6ms"></li></td>
    • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
    • <table id="ae6ms"></table>
    • <td id="ae6ms"></td>
      <td id="ae6ms"></td>
    • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
    • <td id="ae6ms"></td>
    • <table id="ae6ms"><li id="ae6ms"></li></table>
    • <table id="ae6ms"></table>