I am building a wizard and the first step of this wizard is to let the user sele
ID: 645835 • Letter: I
Question
I am building a wizard and the first step of this wizard is to let the user select a file. In the following steps I need this file to display some data from it and as a final step I have to import some content of the selected file.
How can i preserve this file along the steps?
I can save the file on the server in a temp dir (and make sure it is linked to the user's session, so that no other import session will intervene). I can save the file in the session state (Viewbag maybe?) What would you do?
Edit:
The size can vary from 100kb - 10mb
Explanation / Answer
You could use Sessions here but that has a few downsides. The oft-quoted one is the default configuration (in process) is fast but the session dies if the app pool gets restarted. Code-wise this means you typically need to check if your session has not died so you can handle it gracefully. This is fairly easy to do but it is some overhead.
The bigger downside there is the fact that the browser shares a session between all tabs so if someone does some normal modern browser stuff you can get massive confusion or at least UI weirdness. A good example of someone doing something like this would be united airlines -- you can only look at one of your flights at once due to session contention.
The approach I would take here is to have them upload the file, stash it in an appropriate place, generate an ID for it and then keep that in the wizard. When they complete it you can pick up the file at the end. If they start 2 at once it is easy to handle. Stay stateless.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.