我以前一直在记事本中直接编写代码,对于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";
    }}

解决方案 »

  1.   

    在后台编码中直接使用Session即可,不必声明:
    Session( "one" ) = "1" 
      

  2.   

    不用HttpSessionState session = new HttpSessionState();
    Session.Add("one", 0) ;就行
      

  3.   

    当然最好写成
    if (Session.IsNewSession)
    {
      Session.Add("one",0) ;
    }否则,比如你把这个Session.Add("one",0) ;放在了Page_Load中,那么你每次Button1_Click,都会Page_Load,这样就会使Session再次初始化,这样的话,就会出现误差