Guest User

Untitled

a guest
Dec 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public string GetCartId(HttpContextBase context)
  2. {
  3. if (context.Session[CartSessionKey] == null)
  4. {
  5. if (!string.IsNullOrWhiteSpace(context.User.Identity.Name))
  6. {
  7. context.Session[CartSessionKey] =
  8. context.User.Identity.Name;
  9. }
  10. else
  11. {
  12. // Generate a new random GUID using System.Guid class
  13. Guid tempCartId = Guid.NewGuid();
  14. // Send tempCartId back to client as a cookie
  15. context.Session[CartSessionKey] = tempCartId.ToString();
  16. }
  17. }
  18. return context.Session[CartSessionKey].ToString();
  19.  
  20. public string GetCartId(HttpContext context)
  21. {
  22. if (context.Session.GetString(CartSessionKey) == null)
  23. {
  24. if (!string.IsNullOrWhiteSpace(context.User.Identity.Name))
  25. {
  26. context.Session.SetString(CartSessionKey, context.User.Identity.Name);
  27. }
  28. else
  29. {
  30. var tempCartId = Guid.NewGuid();
  31. context.Session.SetString(CartSessionKey, tempCartId.ToString());
  32. }
  33. }
  34.  
  35. return context.Session.GetString(CartSessionKey);
  36. }
Add Comment
Please, Sign In to add comment