【发布时间】:2011-10-21 14:59:39
【问题描述】:
我有以下代码,它使用会话但我在行中有错误:
if (Session["ShoppingCart"] == null)
错误是cS0103: The name 'Session' does not exist in the current context有什么问题?
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Web.SessionState;
/// <summary>
/// Summary description for ShoppingCart
/// </summary>
public class ShoppingCart
{
List<CartItem> list;
public ShoppingCart()
{
if (Session["ShoppingCart"] == null)
list = new List<CartItem>();
else
list = (List<CartItem>)Session["ShoppingCart"];
}
}
【问题讨论】:
-
哪种方法?你的意思是构造函数吗?在另一个班级
-
您从非会话页面或线程中调用它。