Session management in .Net Core
Asked 2 years 8 months 27 days 7 hours 28 minutes  ago, Viewed 2209 times
                Sessions can be used to pass data between controllers and views. This can be compared to global data in a desktop application. Operations that can be performed on session variables:
Read data. if (!string.IsNullOrEmpty(HttpContext.Session.GetString(SessionName)))
 {
     var name = HttpContext.Session.GetString(SessionName);          
 }
 if (!string.IsNullOrEmpty(HttpContext.Session.GetInt32(SessionAge)))
 {
     var age = HttpContext.Session.GetInt32(SessionAge).ToString();         
 }public void setSession()
 {
     HttpContext.Session.SetString("SessionName", "Value");
     HttpContext.Session.SetInt32("SessionAge", 74);
 }
 HttpContext.Session.Remove("SessionName");Session implementation:
Startup.csservices.AddDistributedMemoryCache();
services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromSeconds(10);
    options.Cookie.HttpOnly = true;
    options.Cookie.IsEssential = true;
});
app.UseSession();
                    Like 
          
        
                    12