C
C#11mo ago
Whiteboy

ASP.NET file data not being saved in page

So i need to upload user list from .xslx file and displa yit in a table for adjustments, then send send the users to mySQL db, the problem i have is that after i upload file and try to send ti db the "ExtractedData" returns null
10 Replies
Angius
Angius11mo ago
You're doing some... weird stuff here, like all those Task.FromResult<T>() things Also, properties don't stick around between requests So that's something you need to mind
Whiteboy
WhiteboyOP11mo ago
how do i get around it
Angius
Angius11mo ago
Well, you will need to persist that data somehow. Database, cache, up to you Any particular reason why file upload and sending the file contents to the db are two separate actions in the first place?
Whiteboy
WhiteboyOP11mo ago
because the data needs to be displayed for review then decided if send to db
Angius
Angius11mo ago
Store it temporarily in the cache, then Or save it in the db with an additional property like Approved set to false Then, when accepted, set it back to true And periodically delete data that has Approved=false
Whiteboy
WhiteboyOP11mo ago
string extractedDataJson = JsonSerializer.Serialize(extractedData);
HttpContext.Session.SetString("ExtractedData", extractedDataJson);
string extractedDataJson = JsonSerializer.Serialize(extractedData);
HttpContext.Session.SetString("ExtractedData", extractedDataJson);
string extractedDataJson = HttpContext.Session.GetString("ExtractedData");
if (extractedDataJson != null)
{
var extractedData = JsonSerializer.Deserialize<List<(int UserId, string ClassGroup, string Grupa, string Login, PermissionLevel PermissionLevel)>>(extractedDataJson);
ExtractedData = extractedData;
}
string extractedDataJson = HttpContext.Session.GetString("ExtractedData");
if (extractedDataJson != null)
{
var extractedData = JsonSerializer.Deserialize<List<(int UserId, string ClassGroup, string Grupa, string Login, PermissionLevel PermissionLevel)>>(extractedDataJson);
ExtractedData = extractedData;
}
so i get all null valeus in my table now because for some reason i can't just save a list
Angius
Angius11mo ago
Well you're saving it in the session, so, yeah That's why I said "cache" and not "session"
Whiteboy
WhiteboyOP11mo ago
ah tought it's the same, that's my biggest problem because i never did web and for some reason i have to do website for final project So same with the user list if im gonna have 10k+ users i should cache the data to load it faster right? @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius11mo ago
Why would you need to know all the users at all times?
Whiteboy
WhiteboyOP11mo ago
hmm i don't
Want results from more Discord servers?
Add your server