locked
Cookie problem Shopping cart RRS feed

  • Question

  • Hey,

    I'm creating a shoppingcart.
    When a product is added to the shopping cart I create a GUID for the shoppingcart which is placed into a cookie.
    First a go to the AddToCart.aspx page then I do a redirect to the ShoppingCart.aspx, when I do the redirect a new cookie is created.
    In the shoppingcart I search for the current cookie, based on that I go to my db to get the products connected to that cookie.
    This is a normal way of doing things.

    But the problem is by the redirect form AddToCart & ShoppingCart the current cookie is replaced with on other one.

    With this method I search for the cookie

    public

     

    static string GetCartGUID()

    {

     

    if (HttpContext.Current.Request.Cookies["SBSCommerce"] != null && HttpContext.Current.Request.Cookies["SBSCommerce"]["CartID"] != null)

    {

     

     

    return HttpContext.Current.Request.Cookies["SBSCommerce"]["CartID"].ToString();

    }

     

    else

    {

     

    Guid CartGUID = Guid.NewGuid();

     

    HttpCookie cookie = new HttpCookie("SBSCommerce");

    cookie.Values.Add(

    "CartID", CartGUID.ToString());

    cookie.Expires =

    DateTime.Now.AddDays(30);

     

    HttpContext.Current.Response.AppendCookie(cookie);

     

    return CartGUID.ToString();

    }

    }

    Can somebody please help me ?
    Could it be a problem in the webconfig ?


    Sebastian

    • Moved by nobugz Wednesday, August 19, 2009 12:47 PM forums.asp.net (From:Visual C# General)
    Wednesday, August 19, 2009 12:27 PM

Answers