Use Session in .NET Core MVC

PHOTO EMBED

Mon Dec 25 2023 16:22:36 GMT+0000 (Coordinated Universal Time)

Saved by @abhikash01

Add following Code in Program.CS :
     builder.Services.AddSession(options =>
     {
         options.IdleTimeout = TimeSpan.FromMinutes(30);
     });
app.UseSession();

In Controller use the following Code: 
To get the Session:
 HttpContext.Session.SetString("Name", "John Smith");

To set the Session:
 ViewBag.Name = HttpContext.Session.GetString(sessionName);


content_copyCOPY