Can we enable Session in ASP.NET Core ?if yes then how we can enable Session in ASP.NET Core ?
To enable session in ASP.NET Core you can install Microsoft.AspNetCore.Session package.With this done you can configure it as follows
public void ConfigureServices(IServiceCollection services){ services.AddMvc(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(60); }); }
public void ConfigureServices(IServiceCollection services){
services.AddMvc();
services.AddSession(options => {
options.IdleTimeout = TimeSpan.FromMinutes(60);
});
}
You can access session with HttpContext.Session