title: Access session variable in razor view .net core 2
body: <p>I'm trying to access session storage in a razor view for a .net core 2.0 project. Is there any equivalent for @Session["key"] in a .net 2.0 view? I have not found a working example of how to do this - I am getting this error using the methods I have found:</p>
  
  <blockquote>
    <p>An object reference is required for the non-static field, method, or propery HttpContext.Session</p>
  </blockquote>
  
  <p>View:</p>
  
  <pre><code>@using Microsoft.AspNetCore.Http
  
  [HTML button that needs to be hidden/shown based on trigger]
  
  @section scripts {
  &lt;script&gt;
      var filteredResults = '@HttpContext.Session.GetString("isFiltered")';
  &lt;/script&gt;
  }
  </code></pre>
  
  <p>Startup.cs:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
      {
          services.AddSession(options =&gt; {
              options.IdleTimeout = TimeSpan.FromMinutes(30);
          });
  
          services.AddMvc();
  
          // Added - uses IOptions&lt;T&gt; for your settings.
          // Added - replacement for the configuration manager
      }
  
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          //exception handler stuff
          //rewrite http to https
          //authentication
          app.UseSession();
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
      }
  </code></pre>