Cookie值存储为null

时间:2017-01-12 19:53:13

标签: c# asp.net .net cookies null

public double FindSubTotal()
{
    SqlConnection objConnection;
    SqlCommand objCommand;
    string SQL, s;
    double price;
    objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebsiteAdminConnectionString"].ConnectionString);
    objConnection.Open();
    s = "";
    price = 0.0;
    //SQL = "SELECT  isnull(balance, 0) as balance FROM  PurchaseList where productType=3 AND userID =" + Request.Cookies["customerID"].Value + " ";
    SQL = "SELECT  ISNULL(price, 0) as p FROM tempList where  userID=" + Request.Cookies["customerID"].Value;
    objCommand = new SqlCommand(SQL, objConnection);
    objCommand.Prepare();
    SqlDataReader objDataReader = objCommand.ExecuteReader();

    if (objDataReader.HasRows)
    {
        while (objDataReader.Read() == true)
        {
            price = price + Convert.ToDouble(objDataReader["p"]);
        }
    }
    objConnection.Close();
    return price;
}

public string FindDesc()
{
    SqlConnection objConnection;
    SqlCommand objCommand;
    string SQL, s, items;
    double price;
    objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebsiteAdminConnectionString"].ConnectionString);
    objConnection.Open();
    s = "";
    price = 0.0;
    if (Request.Cookies["mycookie"] == null) return "0";   // I added this to remove the cookies and page loads up.
    //SQL = "SELECT  isnull(balance, 0) as balance FROM  PurchaseList where productType=3 AND userID =" + Request.Cookies["customerID"].Value + " ";
    SQL = "SELECT  ISNULL(price, 0) as p, quantity, productName FROM tempList where  userID=" + Request.Cookies["customerID"].Value;
    objCommand = new SqlCommand(SQL, objConnection);
    objCommand.Prepare();
    SqlDataReader objDataReader = objCommand.ExecuteReader();
    items = "";

    if (objDataReader.HasRows)
    {

        while (objDataReader.Read() == true)
        {
            price = Convert.ToDouble(objDataReader["p"]);
            items = items + " DESC: " + Convert.ToString(objDataReader["productName"]).Replace("'","").Replace(@"""","").Replace(@"™","") + " QTY: " + Convert.ToString(objDataReader["quantity"]) + " $" + price.ToString("N");
        }
    }
    objConnection.Close();
    return items;
}

这是一个页面 - viewbasket.aspx.cs。当我点击viewbasket按钮时显示错误,发现这是由于传递给cookie的null值并使用了代码提到的"删除cookies"试图清除它。现在我遇到了一个问题,因为request.cookies是空的,无法在字符串被清空时将项目添加到购物车。

已经设置了唯一ID" customerID"饼干。 请帮助我这个人,我不熟悉asp.net。但只需要修复此问题。提前谢谢我的朋友们

0 个答案:

没有答案