Mvc4.0 提取 Cookie 里的东西
/// <summary> /// 提取Cookie /// </summary> /// <returns></returns> public static List<ShoppingGoods> TiQuCookies() { ShoppingMallContext db = new ShoppingMallContext(); List<ShoppingGoods> listgoods = new List<ShoppingGoods>(); var allgoods = HttpContext.Current.Request.Cookies["MyShoppingCart"]; if (allgoods == null) { return null; } else { string agoods = allgoods.Value; agoods = agoods.Substring(0, agoods.Length - 1); var agods = agoods.Split(','); for (int i = 0; i < agods.Count(); i++) { var spt = agods[i].Split('-'); string skuID = spt[0]; int skuid = 0; bool parseSkuIdOK = int.TryParse(skuID, out skuid); string skuCount = spt[1]; int skuCont = 0; bool parseSkuCountOK = int.TryParse(skuCount, out skuCont); if (parseSkuIdOK == false || parseSkuCountOK == false) { return null; } else { ShoppingGoods sc = new ShoppingGoods(); var goods = db.GoodsSKUs .Where(f => f.GoodsSkuID == skuid) .Select(f => f.GoodsID).ToArray()[0]; var goodsSKU = db.GoodsSKUs .Where(f => f.GoodsSkuID == skuid) .Single(); var gs = db.Goodss .Where(f => f.GoodsID == goodsSKU.GoodsID) .Select(f => f.GoodsName); sc.GoodsName = gs.ToArray()[0]; sc.Count = skuCont; sc.Goodssku = goodsSKU; listgoods.Add(sc); } } return listgoods; } }