我以前一直在记事本中直接编写代码,对于session,都是直接使用的,不过到了VS里后,我都不知道如何用session了,直接声明吧,比如我声明了
HttpSessionState session = new HttpSessionState()
会说我“ 重载“HttpSessionState”方法未获取“0”参数 ”,那如何在CS文件中使用啊?public class WebForm1 : System.Web.UI.Page
{
HttpSessionState session = new HttpSessionState();
private void Button1_Click(object sender, System.EventArgs e)
{
session[ "one" ] = "1";
}}
HttpSessionState session = new HttpSessionState()
会说我“ 重载“HttpSessionState”方法未获取“0”参数 ”,那如何在CS文件中使用啊?public class WebForm1 : System.Web.UI.Page
{
HttpSessionState session = new HttpSessionState();
private void Button1_Click(object sender, System.EventArgs e)
{
session[ "one" ] = "1";
}}
Session( "one" ) = "1"
Session.Add("one", 0) ;就行
if (Session.IsNewSession)
{
Session.Add("one",0) ;
}否则,比如你把这个Session.Add("one",0) ;放在了Page_Load中,那么你每次Button1_Click,都会Page_Load,这样就会使Session再次初始化,这样的话,就会出现误差