title: AspNet Core 2 No service for type 'Microsoft.AspNetCore.Http.HttpContext' sessions issue
body: <p>im using AspNet Core 2 to build an app, im having problems with sessions, can you please help?</p>
  
  <p>exact error:</p>
  
  <p><strong>No service for type 'Microsoft.AspNetCore.Http.HttpContext' has been registered.</strong></p>
  
  <p>im using <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-2.1&amp;tabs=aspnetcore2x" rel="nofollow noreferrer">this</a> as guide, but seems to be not enough.</p>
  
  <p>in Startup.cs</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.AddDistributedMemoryCache();
              services.AddMvc().AddSessionStateTempDataProvider();
              services.AddSession(options =&gt;
              {
                  // Set a short timeout for easy testing.
                  options.IdleTimeout = TimeSpan.FromMinutes(1);
                  options.Cookie.HttpOnly = true;
              });//&lt;&lt;==
          }
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseBrowserLink();
              }
              else
              {
                  app.UseExceptionHandler("/Home/Error");
              }
          app.UseStaticFiles();
  
          app.UseSession();//&lt;&lt;==
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
  
              routes.MapSpaFallbackRoute(
                  name: "spa-fallback",
                  defaults: new { controller = "Home", action = "Index" });
          });
      }
  </code></pre>
  
  <p>in home controller:</p>
  
  <pre><code>using Microsoft.AspNetCore.Http;
  
  HttpContext.Session.SetString("TestName", user.UserName);
  HttpContext.Session.SetString("TestVal", user.testVal.ToString());
  </code></pre>
  
  <p><strong>to this point it seems to be working</strong>, im able to navigate through different pages and i can use/check sessions in controller side.</p>
  
  <p>But the problem is when im trying to use sessions in any view</p>
  
  <p>View side:</p>
  
  <pre><code>@using Microsoft.AspNetCore.Http
  @inject HttpContext HttpContext
  
  
  @if (@HttpContext.Session.GetString("testVal").Equals("True"))
  {
  &lt;td&gt;&lt;input type="checkbox"&gt;&lt;/td&gt;
  }
  else
  {
  &lt;td&gt;&lt;input type="checkbox" readonly&gt;&lt;/td&gt;
  }  
  </code></pre>
  
  <p>when i try to get or set sessions cshtml/view side i get the error</p>
  
  <p>can you please help?</p>