I am trying to write and read the session data, but it is not working somehow. Due to long data, I have got a fetch request every 20sec to get the processed row numbers from the loop. But it returns ZERO all the time.
I can get read the row number from Session, when it is inside the WRITE method but it is always ZERO inside the READ Method. Isn't Session data global and readable from any method?
var ExcelCount = HttpContext.Session.GetInt32("ProductExcelCount") ?? 0;
//CONTROLLER
//WRITE
[HttpPost]
public IActionResult DownloadExcel([FromBody] filter)
{
HttpContext.Session.SetInt32("ProductExcelCount", 0);
//......
//Code incremates progressed row number
HttpContext.Session.SetInt32("ProductExcelCount", rowNo);
//.....
var FileName = $"Template.xlsx";
return File(content, contentType, FileName);
}
//READ
public JsonResult DownloadProgress()
{
var ExcelCount = HttpContext.Session.GetInt32("ProductExcelCount") ?? 0;
return Json(new { downloadData = new { ExcelCount } });
}
//JavaScript Read Session
"downloadData": function() {
getFileFromTheServer();
setInterval(this.downloadProgress, 20000);
},
"downloadProgress": function() {
getProgressFromTheServer();
},