title: Session variable gets set in VB.NET but not in C#
body: <p>I'm using ASP.NET for a project. I'm trying to set a session variable and access its value in the aspx file.</p>
  
  <p>In VB.NET, I set the session variable like this:</p>
  
  <pre><code>Partial Class MainSite_Default
      Inherits System.Web.UI.Page
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          Session("TestVariable") = "Lorem ipsum"
      End Sub
  End Class
  </code></pre>
  
  <p>And in the corresponding aspx file, I can access its value using <code>&lt;%=Session("TestVariable")%&gt;</code>.</p>
  
  <p>This works fine. But, now let's say I rewrite this in C#, and try to set the session variable similarly:</p>
  
  <pre><code>public partial class Mainsite_Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e) {
          Session["TestVariable"] = "Lorem ipsum";
      }
  }
  </code></pre>
  
  <p>And once again, in the aspx file, I try to access its value using <code>&lt;%=Session["TestVariable"]%&gt;</code>.</p>
  
  <p>In this case, <code>Session["TestVariable"]</code> is null. The value doesn't seem to get assigned. I've also tried changing <code>Session</code> to <code>HttpContext.Current.Session</code> with no luck.</p>
  
  <p>Am I setting the session variable wrong in C#?</p>
  
  <p>Interestingly, if I set the session variable in the MasterPageFile, I can then access it in the aspx file. But not if I place it in the <code>Page_Load</code> method of my <code>Mainsite_Default</code> class. However, if I set the variable in the <code>Page_Load</code> method in VB.NET, it works fine.</p>