title: What do you have to do to get sessions working in MVC5?
body: <p>What do you have to do to get sessions working in MVC5? In MVC4 I can create a new project and add </p>
  
  <pre><code>Session["TEST"] = "worked";
  </code></pre>
  
  <p>to a controller and it works without any issues. If I do that in an MVC5 project it works fine in Visual Studio 2012, but when I deploy it to IIS I get a 
  "System.NullReferenceException" exception. </p>
  
  <p>Updated Information:</p>
  
  <p>I have MVC5 running in VS 2012 without issue. I installed all the updates to get that working and have everything working except for sessions. I don't think that MVC5 is the issue, I think it's something about the project template that differs from the MVC4 template.</p>
  
  <p>Here is my controller action that's causing the issue:</p>
  
  <pre><code>    public ActionResult Index()
      {
          ViewBag.Message = "Modify this template.";
          Session["TEST"] = "worked";
          return View();
      }
  </code></pre>
  
  <p>Potential fix:</p>
  
  <p>Adding <strong>runAllManagedModulesForAllRequests="true"</strong> to my web.config fixes the issue.</p>
  
  <pre><code>&lt;modules runAllManagedModulesForAllRequests="true"&gt;
  </code></pre>
  
  <p>I can also do the suggested answer here:</p>
  
  <p><a href="https://stackoverflow.com/questions/1161351/asp-net-mvc-error-with-configured-managed-modules">Asp.net MVC error with configured managed modules</a></p>
  
  <pre><code>&lt;remove name="Session" /&gt;
  &lt;add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" /&gt;
  </code></pre>
  
  <p>And that fixes my issue as well. Can anyone provide me some further reading on which one is a better solution and why?</p>