title: C# Session Variable works only in method
body: <p>I am creating Session Variable in my ActionResult method and it works fine within this method but whenever I make a call from other method in the same Controller I get Null Reference. I read a lot of questions here and nothing really helped me. No idea what could cause this issue. If You would have any ideas on that I would be really thankful for answer. </p>
  
  <p>Might help: </p>
  
  <ul>
  <li>The retrieve is happening on Button Click from user. But I don't think it changes anything.</li>
  <li>It also won't work in another method that is not called on button click.</li>
  <li>Method in which I retrieve it is a void method.</li>
  <li>It is not a timeout issue for sure. I added timeout before and did not help.</li>
  </ul>
  
  <p>In this specific example I am using List object, but it goes the same way with any other object I will assign to Session.</p>
  
  <p>Declaration:</p>
  
  <pre><code>  List&lt;Thread&gt; tList = Session["tList"] as List&lt;Thread&gt;;
          if (tList == null)
          {
              tList = new List&lt;Thread&gt;();
              Session["tList"] = tList;
          }
  </code></pre>
  
  <p>Fail Retrive in other method:</p>
  
  <pre><code> var t = new Thread(() =&gt;
          {
              foreach (var item in Session["tList"] as List&lt;Thread&gt;)
              {
                  try
                  {
                      item.Abort();
                  }
                  catch (Exception)
                  {
                  }
              }
          });
  </code></pre>
  
  <p>web.config(The whole system.web section since maye there is something else blocking it. No idea):</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms cookieless="UseCookies" loginUrl="~/user/login" slidingExpiration="true"&gt;&lt;/forms&gt;
  &lt;/authentication&gt;
  &lt;compilation debug="true" targetFramework="4.5" /&gt;
  &lt;httpRuntime targetFramework="4.5" /&gt;
  &lt;httpModules&gt;&lt;/httpModules&gt;
  &lt;sessionState cookieless="true" regenerateExpiredSessionId="true" /&gt;
  </code></pre>