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);