电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

用Session和Cookie两种方法实现购物车

用Session和Cookie两种方法实现购物车_第1页
1/8
用Session和Cookie两种方法实现购物车_第2页
2/8
用Session和Cookie两种方法实现购物车_第3页
3/8
asp.net 中购物车的两种存储方式 Session 和 Cookie 的应用实例 收藏 1.这是用 Cookie 存储的购物车的几种常用的操作: /// /// 使用 Cookie 的购物车 /// public class CookieCar { public const string COOKIE_CAR = "Car"; //cookie 中的购物车 /// /// 无参数的构造方法 /// public CookieCar() { } /// /// 添加商品到购物车 /// /// /// public void AddProductToCar(string id, string quantity) { string product = id + "," + quantity; //购物车中没有该商品 if (!VerDictCarIsExit(id)) { string oldCar = GetCarInfo(); string newCar = null; if (oldCar != "") { oldCar += "|"; } newCar += oldCar + product; AddCar(newCar); } else { int count = int.Parse(GetProductInfo(id).Split(',')[1].ToString()); UpdateQuantity(id, count + 1); } } /// /// 添加商品的数量 /// /// public void UpdateQuantity(string id, int quantity) { //得到购物车 string products = GetCarInfo(); products = "|" + products + "|"; string oldProduct = "|" + GetProductInfo(id) + "|"; if (products != "") { string oldCar = GetCarInfo(); string newProduct = "|" + id + "," + quantity + "|"; products = products.Replace(oldProduct, newProduct); products = products.TrimStart('|').TrimEnd('|'); AddCar(products); } } /// /// 得到购物车 /// /// public string GetCarInfo() { if (HttpContext.Current.Request.Cookies[COOKIE_CAR] != null) { return HttpContext.Current.Request.Cookies[COOKIE_CAR].Value.ToString(); } return ""; } /// /// 根据ID 得到购物车中一种商品的信息 /// /// /// private string GetProductInfo(string id) { string productInfo = null; //得到购物车中的所...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

用Session和Cookie两种方法实现购物车

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部