title: Session variable value is getting null in ASP.NET Core
body: <p>I am setting a session variable in one method and trying to get the session variable value from the another method in a controller but its always getting null:</p>
  
  <p><strong>Here is my code:</strong></p>
  
  <pre><code>public class HomeController : Controller
  {
      public IActionResult Index()
      { 
          HttpContext.Session.SetString("Test", "Hello!");
          var message = HttpContext.Session.GetString("Test");// Here value is getting correctly
          return View();
      }
  
      public IActionResult About()
      {
          var message = HttpContext.Session.GetString("Test"); // This value is always getting null here
  
          return View();
      }
  }
  </code></pre>
  
  <p><strong>Here is my session configuration in <code>Startup</code> class:</strong></p>
  
  <p><em>In <code>ConfigureServices()</code> method:</em></p>
  
  <pre><code>services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
  {
      // This lambda determines whether user consent for non-essential cookies is needed for a given request.
      options.CheckConsentNeeded = context =&gt; true;
      options.MinimumSameSitePolicy = SameSiteMode.None;
  });
  
  services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  services.AddDistributedMemoryCache();
  services.AddMvc().AddSessionStateTempDataProvider();
  services.AddSession(options =&gt;
  {
      options.Cookie.Name = "TanvirArjel.Session";
      options.IdleTimeout = TimeSpan.FromDays(1);
  });
  </code></pre>
  
  <p><em>In <code>Configure()</code> method:</em></p>
  
  <pre><code>app.UseSession();
  app.UseMvc(routes =&gt;
  {
      routes.MapRoute(
          name: "default",
          template: "{controller=Home}/{action=Index}/{id?}");
  });
  </code></pre>
  
  <p><strong>Very strange and peculiar problem! Any help will be highly appreciated!</strong></p>