Where I should declare a session variable in asp.net

后端 未结 5 633
醉话见心
醉话见心 2021-01-02 14:33

I am building a Asp.net Application. I need to save a HashTable in a session.

At page load i am writing

 protected void Page_Load(object sender, Even         


        
5条回答
  •  -上瘾入骨i
    2021-01-02 15:09

    test if it exists first

     protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           if(Session["AttemptCount"] == null)
           {
              Session["AttemptCount"]=new Hashtable(); //Because of this line.
           }
        }   
    }
    

    though the session_start is better, you only need to uses it on one page but you can create it for each session.

提交回复
热议问题