“会话”不会在目前情况下存在 [英] 'Session' does not exist in the current context
本文介绍了“会话”不会在目前情况下存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的code,使用会话,但我必须在该行的错误:
如果(会话[我的购物] == NULL)
误差 cS0103:会话名称不会在当前的背景下存在
是什么问题。
使用系统;
使用System.Data这;
使用System.Configuration;
使用System.Linq的;
使用的System.Web;
使用System.Web.Security;
使用System.Web.UI程序;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Xml.Linq的;使用System.Collections.Generic;
使用System.Web.SessionState;
///<总结>
///对我的购物摘要说明
///< /总结>
公共类的购物车
{
清单< CartItem>清单;
市民购物车()
{
如果(会话[我的购物] == NULL)
名单=新名单,LT; CartItem>();
其他
名单=(列表< CartItem>)会议[我的购物];
}
}
解决方案
的问题是,您的类未从继承页。结果
更改
公共类的购物
公共类的购物:页
和它的工作。
I have the following code, that uses session but i have an error in the line :
if (Session["ShoppingCart"] == null)
the error is cS0103: The name 'Session' does not exist in the current context
what is the problem ?
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"];
}
}
解决方案
The issue is that your class does not inherit from Page.
Change
public class ShoppingCart
to public class ShoppingCart : Page
and it will work
这篇关于“会话”不会在目前情况下存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文