title: session variables lost for some reason
body: <p>I try to setup a E-shop. Next to every item I've an <code>asp:imagebutton</code> when this imagebutton is clicked I'm checking whehter the session varialbe <code>session["basket"]</code> exists or not if not then I add the values in a list (entity class) and I add this list in the session. </p>
  
  <p>if the session is not empty then I retrieve the values from session into List and change the list and then add the list back to session.</p>
  
  <p><strong>Issue:</strong></p>
  
  <p>For some reason I loose the session variable, suddenly.  I checked on my watch (time) and it's unpredicatble  sometimes it takes less than 1 minute, sometimes 3 minutes and sometimes 5 minutes etc.... </p>
  
  <p>why do I loose the session variable? </p>
  
  <p>I googled and I've found - it can happen if you use <code>Response.Redirect</code> - w/o false parameter, or if you're in an <code>UpdatePanel</code> etc. </p>
  
  <p>I'm loosing the variable in the same page for the moment.  </p>
  
  <p>The whole idea is put in a session variable and do checkout and retrieve the session variable in second <code>aspx</code> page... but this is not always working, because most of the case the session variables becomes empty. And sometimes it works.</p>
  
  <p>can someone advice ? what and where do I need to check? 
  In some website pages (google) they advice to use caching, but caching is application based, so everybody will retrieve the same value.</p>
  
  <p>In my page any user (authenticated or anynomous user) in other words any user without login should able to order (I'll send invoice to pay upfront)....</p>
  
  <p>I''m not using webfarm, nor web garden... I just checked the IIS - website - session state - It's in process, cookie settings = use cookies, name = asp.net_sessionid, time-out = 20.... </p>
  
  <p>please advice?</p>
  
  <p>It's <code>C#</code>, <code>ASPX 3.5</code>, <code>IIS7.5</code></p>
  
  <p>I DON't have PAGE_LOAD  in my ASPX page.</p>
  
  <p>//  the only place I put the sessoin=null is a linkbutton, for the rest I don't put null in session["basket"].... </p>
  
  <pre><code>protected void lnkDeleteAllSelected_Click(object sender, EventArgs e)
      {
          Session["Basket"] = null;
          ReloadBasketItems();
  
      }
  
   protected override void OnInit(EventArgs e)
      {
  
          base.OnInit(e);
          //System.Diagnostics.Debugger.Break();
  
          lvJuridisch.ItemDataBound += new EventHandler&lt;ListViewItemEventArgs&gt;(this.lv_ItemDataBound);
          lvJuridisch.DataBound += new EventHandler(lv_DataBound);
  
      }
  </code></pre>
  
  <p>imgButtonAddtoBasket -> is defined as asp:imagebutton in the asp:listview</p>
  
  <pre><code> protected void imgButtonAddtoBasket_Click(object sender, ImageClickEventArgs e)
      {
          ListViewDataItem lvi = ((sender as ImageButton).NamingContainer) as ListViewDataItem;
          DataKey currentDataKey = (lvi.NamingContainer as ListView).DataKeys[lvi.DataItemIndex];
          WebShopInfo SingleItem = new WebShopInfo();
          SingleItem.cd_type_pub = currentDataKey[0].ToString();
          SingleItem.no_pub = currentDataKey[1].ToString();
          SingleItem.no_suite_pub = Convert.ToInt32(currentDataKey[2]);
          SingleItem.cd_langue = Convert.ToChar(currentDataKey[3]);
          SingleItem.lb_titre_red = (lvi.FindControl("HiddenfieldProductRed") as HiddenField).Value;
  
          SingleItem.m_price = Convert.ToDecimal((lvi.FindControl("hiddenField_M_Price") as HiddenField).Value);
          SingleItem.nm_price = Convert.ToDecimal((lvi.FindControl("hiddenField_NM_Price") as HiddenField).Value);
          SingleItem.mt_pourc_tva = Convert.ToDecimal((lvi.FindControl("hfBTW") as HiddenField).Value);
  
  
          List&lt;WebShopInfo&gt; lws = new List&lt;WebShopInfo&gt;();
          if (Session["Basket"] == null)
          {
  
              //Session is empty so add listview to the session....
              //Session.Timeout = 20;  -- I tried this but this is not working too...
              lws.Add(SingleItem);
              Session["Basket"] = lws;
          }
          else
          {
              //Session is not empty so get asp:listview from the session.
              lws = Session["Basket"] as List&lt;WebShopInfo&gt;;
  
              WebShopInfo wsi = lws.Where(a =&gt; a.cd_type_pub == SingleItem.cd_type_pub &amp;&amp;
                                              a.no_pub == SingleItem.no_pub &amp;&amp;
                                              a.no_suite_pub == SingleItem.no_suite_pub &amp;&amp;
                                              a.cd_langue == SingleItem.cd_langue).SingleOrDefault&lt;WebShopInfo&gt;();
              if (wsi != null)
                  lws.Remove(wsi);
  
              if (SingleItem.Count &gt; 0)
                  lws.Add(SingleItem);
              Session["Basket"] = lws;
          }
  
          ReloadBasketItems();
      }
  </code></pre>