Last post Feb 02, 2021 07:00 AM by Mikesdotnetting
Feb 01, 2021 03:16 PM|IGieckI|LINK
In the project i am developing a file is saved in a Session, after that moment that object is only read, however sometimes (because it does not always happen) that Session becomes null, looking online i have already found a solution that uses databases but
this it is a school project and we have not yet arrived at implementing a database. What should i do? Thanks in advance.
Feb 01, 2021 07:52 PM|francissvk|LINK
Hi IGieckl, Storing large object in Session like Files in not a recommended way to use. So try to use Database. Since you don't want to go with DB also in that case read the file whenever you want. It will be better choice.
Hope this helps!
Feb 02, 2021 07:00 AM|Mikesdotnetting|LINK
Sessions are volatile and can be lost for a number of reasons including memory pressure on the web server, app pools recycling and applications restarting. You should always check whether a session item for null before you try to access it. If it is null,
load the item into session again.
if(Session["file"] == null)
Session["file"] = File.ReadAllText("/somefile");
var fileContent = Session["file"];