title: Enabling Session State in ASP.NET MVC
body: <p>I'd like to use session variables in my ASP.NET MVC application.</p>
  
  <p>I already added the <code>&lt;sessionState&gt;</code> tag in my <code>web.config</code> file like this</p>
  
  <pre><code>&lt;sessionState mode="InProc" cookieless="false" timeout="20"&gt;
      &lt;/sessionState&gt;
  </code></pre>
  
  <p>I get a session ID in my url like this if I use <code>cookieless="true"</code></p>
  
  <pre><code>http://localhost:2967/%28S%28hcawmi55zoruuy453fbo3k55%29%29/RmdReqBankAccount
  </code></pre>
  
  <p>But I still can't use session variables in my application.</p>
  
  <p>I set the variable like this in my login method:</p>
  
  <pre><code>Session["username"] = userName;
  </code></pre>
  
  <p>and I retrieve it like this</p>
  
  <pre><code>string user_id = (string)Session["username"];
  </code></pre>
  
  <p>I get an empty string when trying to retrieve values.</p>