title: The Session object is null in ASP.NET MVC 4 webapplication once deployed to IIS 7 (W 2008 R2)
body: <p>I developed an ASP.NET MVC 4 web application (.net 4.5) which runs fine in Visual Studio 2012. After deployment to IIS 7 on Windows Server 2008 R2, it seems like the HttpContext.Session object inside my controller is null. I created a simple test ASP.NET MVC 4 application to demonstrate the issue.</p>
  
  <p>In my test app I have a simple Home Controller</p>
  
  <pre><code>public class HomeController : Controller
  {
      public ActionResult Index()
      {
            if ( HttpContext != null &amp;&amp; HttpContext.Session != null )
            {
                HttpContext.Session[ "test" ] = "a string in session state";
                ViewBag.Info = HttpContext.Session[ "test" ];
                return View();
            }
            else
            {
                if ( HttpContext == null )
                {
                    ViewBag.Info = "beeeeuuuuu - HttpContext = null!!!";
                }
                else if ( HttpContext.Session == null )
                {
                      ViewBag.Info = "beeeeuuuuu - Session = null!!!";
                }
                return View();
            }
  
      }
  }
  </code></pre>
  
  <p>My Index.chtml view lookes something like this:</p>
  
  <pre><code>@{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  This is a simple test
  &lt;p&gt;@ViewBag.Info&lt;/p&gt;
  </code></pre>
  
  <p>So when I run the application I get what I was expecting:</p>
  
  <pre><code>Index
  This is a simple test 
  a string in session state
  </code></pre>
  
  <p>But after I deploy the application to the web server the website gives me the following page indicating that the Session object is null:</p>
  
  <pre><code>Index
  This is a simple test 
  beeeeuuuuu - Session = null!!!
  </code></pre>
  
  <p>The web application is deployed to the default website which runs under the ASP.NET v4.0 application pool (integrated pipeline).</p>
  
  <p>I already reïnstalled ASP.NET on the server using aspnet_regiis -ir but this didn't help. The Session state is enabled (In Proc) at the ISS server. I hope anyone can help me out here cause I'm trying to solve this for quite some time. </p>
  
  <p>Much thanks in advance and kind regards.</p>
  
  <p>UPDATE: I also tested an ASP.NET MVC 4 build with .NET 4.0 instead of 4.5 and that has the same problem. I also deployed an ASP.NET Web Pages app (.NET 4.0) and that works fine (The HttpContext.Current.Session is not null in the code behind).</p>
  
  <p>UPDATE II: I also tried to store the Session State in a database, which worked fine on my development machine but had the same problem on the production server (HttpContext.Session still returns null).</p>