Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get HttpContext.Current.Session in ASP.NET Core?

Tags:

asp.net-core

I need to migrate an MVC project to .net Core, I know it has System.Web removed from ASP.net Core. I need to convert HttpContext.Current.Session ["name"]! = Null at asp.net core. I added: using Microsoft.AspNetCore.Http but I have an error.

like image 819
user3296338 Avatar asked Oct 20 '25 15:10

user3296338


1 Answers

Use like this:

HttpContext.Session.SetString("priceModel", JsonConvert.SerializeObject(customobject));
var priceDetails = HttpContext.Session.GetString("priceModel");

Make sure below points in startup class:

  1. AddSession in ConfigureServices method

    services.AddSession();
    
  2. Usesession in configure method:

    app.UseSession();
    
like image 70
Always_a_learner Avatar answered Oct 23 '25 09:10

Always_a_learner