Asp.net mvc 5 使用会话控制购物车

Asp.net mvc 5 使用会话控制购物车,asp.net-mvc-5,session-cookies,session-state,Asp.net Mvc 5,Session Cookies,Session State,我的购物车在localhost中运行良好,但当我在云主机中托管时,它运行不正常。问题是,当我单击“添加到购物车”按钮时,它将添加一个数量相同的产品,但当我再次在购物车中添加另一个产品时,它将覆盖上一个产品,并在我最后添加时,在购物车中仅显示一个产品。。我不知道会话有什么问题,我想它会再次覆盖会话。另一个问题是,我的更新购物车按钮的功能和购物车中的删除按钮功能不起作用 Object reference not set to an instance of an object. 我有一个控制器名sh

我的购物车在localhost中运行良好,但当我在云主机中托管时,它运行不正常。问题是,当我单击“添加到购物车”按钮时,它将添加一个数量相同的产品,但当我再次在购物车中添加另一个产品时,它将覆盖上一个产品,并在我最后添加时,在购物车中仅显示一个产品。。我不知道会话有什么问题,我想它会再次覆盖会话。另一个问题是,我的更新购物车按钮的功能和购物车中的删除按钮功能不起作用

Object reference not set to an instance of an object.
我有一个控制器名shoppingCartController这是代码

namespace Medi.Areas.User.Controllers
{
public class ShoppingCartController : Controller
{
    ArrayList arr = new ArrayList();
    int id;


    BLL.IRepository<tbl_Product> de = new BLL.IRepository<tbl_Product>();
    public ActionResult Index()
    {
        return View();
    }
    private int isExisting(int id)
    {
        List<Items> cart = (List<Items>)Session["cart"];
        for (int i = 0; i < cart.Count; i++)
            if (cart[i].Pr.ProductID == id)
                return i;
        return -1;


    }
    public ActionResult Delete(int id)
    {
        int index = isExisting(id);
        List<Items> cart = (List<Items>)Session["cart"];
        cart.RemoveAt(index);
        Session["cart"] = cart;
        return PartialView("_pvCart");
    }
    public ActionResult OrderNow(string q)
    {
        if (Session["cart"] == null)
        {
            List<Items> cart = new List<Items>();
            cart.Add(new Items(de.GetById(Convert.ToInt32(q)), 1));
            Session["cart"] = cart;
            // ViewBag.quantity = new MultiSelectList(cart,"Quantity","Quantity");
            //  cart[1]

        }
        else
        {
            id = Convert.ToInt32(q);
            List<Items> cart = (List<Items>)Session["cart"];
            int index = isExisting(id);
            if (index == -1)
                cart.Add(new Items(de.GetById(id), 1));
            else
                cart[index].Quantity++;
            Session["cart"] = cart;
            // ViewBag.quantity = new MultiSelectList(cart, "Quantity", "Quantity");
        }

        return View("Cart");
    }
    [HttpPost]
    public ActionResult UpdateCart(int[] ProductID,int [] quantity )
    {
        int[] x = new int[4];
        int[] y = new int[4];
        List<Items> cart = (List<Items>)Session["cart"];
        for (int i = 0; i < cart.Count; i++)
        {
            x[i] = ProductID[i];
            y[i] = quantity[i];
            updcart(x[i],y[i]);
        }

        Session["cart"] = cart;
        return PartialView("_pvCart");

    }

    public void updcart(int id,int quantity) {
        List<Items> cart = (List<Items>)Session["cart"];
        int index = isExisting(id);
        if (index == -1)
            cart.Add(new Items(de.GetById(id), 1));
        else
            cart[index].Quantity = quantity;
        Session["cart"] = cart;
    }
}
 }
我也在web.config中编写了这段代码

<httpCookies httpOnlyCookies="true" requireSSL="true"/>
<sessionState mode="InProc"/>


请有人帮帮我..请有人帮帮我。。
@using Medi.Models;

<script src="~/Scripts/metro.min.js"></script>
<table class="table hovered" cellpadding=" 2" cellspacing="2" border="1px">
<tr class="info">
    <th></th>

    <th>Name</th>
    <th>Price</th>
    <th>Quantity</th>
    <th>Sub Total</th>
</tr>
@{
    decimal s = 0;
}
@foreach (Items item in (List<Items>)Session["cart"])
{
    <input id="ProductID" name="ProductID" type="hidden" value="@item.Pr.ProductID" />
    s = s + (Convert.ToInt32(item.Pr.Price) * item.Quantity);
    <tr>

        <th>@Ajax.ActionLink("Delete", "Delete", new { id = item.Pr.ProductID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "MyData", InsertionMode = InsertionMode.Replace }, new { @class = "mif-cross" })</th>

        <td>@item.Pr.ProductName</td>
        <td>@item.Pr.Price</td>
        <td>
            <input name="quantity" id="quantity" type="text" style="width:25px;" value="@item.Quantity" />



        </td>
        <td>@(item.Pr.Price * item.Quantity)</td>
    </tr>
}
</table><br />
<hr />
<table cellpadding="1px" cellspacing="1px" style="float:right;">
<tr align="center" colspan="5" style="background-color:gray;">
    <td><h3 style="padding:1px;">Total</h3></td>
    <td> <h3 style="padding:1px;">Rs @s</h3></td>

</tr>
</table>
using BOL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

 namespace Medi.Models
{
 public class Items
{
    tbl_Product pr = new tbl_Product();

    public tbl_Product Pr
    {
        get { return pr; }
        set { pr = value; }
    }
    int quantity;

    public int Quantity { get; set; }
    public Items()
    {

    }
    public Items(tbl_Product product, int quantity)
    {
        this.Pr = product;
        this.Quantity = quantity;
    }
}
 }
<httpCookies httpOnlyCookies="true" requireSSL="true"/>
<sessionState mode="InProc"/>