add the package "Microsoft.AspNet.Session": "1.0.0-beta8" to project.json, and then using Microsoft.AspNet.Http;
inside this namespace you have extension methods for the context.
you also need to use it with DI on Startup.cs :
public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSession(); }
Here's an example of a controller:
using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc; namespace MvcWebApp.Controllers { [Route("[controller]")] public class SomeController : Controller { public async Task<IActionResult> Edit() { HttpContext.Session.SetInt("myVar", 35); } } }
source share