分享是一种美德 --(1)下面是购物车类 namespace XR.Web { using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Web; public class CookieShoppingCart { public CookieShoppingCart() { } /// <summary> /// 将商品信息添加到购物篮 /// </summary> /// <param name="ProductID">商品编号</param> /// <param name="Amount">数量</param> public static void AddShoppingCart(int ProductID, int Amount) { if (HttpContext.Current.Request.Cookies["ShoppingCart"] == null) { HttpCookie MyCookies = new HttpCookie("ShoppingCart"); MyCookies.Expires.AddDays(1); MyCookies.Value = ProductID.ToString() + "*" + Amount.ToString(); HttpContext.Current.Response.Cookies.Add(MyCookies); } else { bool bExists = false; char[] sep = { ',' }; HttpCookie MyCookie = (HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"]; MyCookie.Expires = DateTime.Now.AddDays(1); string sProdID = MyCookie.Value.ToString(); string[] arrCookie = sProdID.Split(sep); //查看cookie中是否有该产品 string newCookie = ""; for (int i = 0; i < arrCookie.Length; i++) { // if (arrCookie[i].Length != 0) { if (arrCookie[i].Trim().Remove(arrCookie[i].IndexOf('*')) == ProductID.ToString().Trim()) { bExists = true; //得到数量 string amountStr = arrCookie[i].Trim().Substring(arrCookie[i].Trim().IndexOf('*') + 1); amountStr = (Convert.ToInt32(amountStr) + Amount).ToString(); arrCookie[i] = arrCookie[i].Trim().Remove(arrCookie[i].IndexOf(