'Session' does not exist in the current context
You either need to convert your class to a Page
by inheriting from Page
, or have the Session
passed in, or use HttpContext.Current.Session
.
Use
if (HttpContext.Current == null ||
HttpContext.Current.Session == null ||
HttpContext.Current.Session["ShoppingCart"] == null)
instead of
if (Session["ShoppingCart"] == null)
The issue is that your class does not inherit from Page. you need to Change
public class ShoppingCart
to
public class ShoppingCart : Page
and it will work