ntobeko Shezi

ntobeko Shezi

  • NA
  • 14
  • 1.2k

Cookies in a shopping cart

Sep 19 2018 6:48 AM
How to allow cookies in a shopping cart so that the customer can be able to view items in the cart that he/she did add into the cart, I did try something like this
 
// We're using HttpContextBase to allow access to cookies.
public string GetCartId(HttpContextBase context)
{
if (context.Session[CartSessionKey] == null)
{
if (!string.IsNullOrWhiteSpace(context.User.Identity.Name))
{
context.Session[CartSessionKey] =
context.User.Identity.Name;
}
else
{
// Generate a new random GUID using System.Guid class
Guid tempCartId = Guid.NewGuid();
// Send tempCartId back to client as a cookie
context.Session[CartSessionKey] = tempCartId.ToString();
}
}
return context.Session[CartSessionKey].ToString();
}

Answers (1)