Oleg Sh
Oleg Sh

Reputation: 9001

ASP.NET MVC - way to pass data between requests

I have controller with 2 methods. First method should set variable and do something. Second method (called by ajax) should get value of this variable. So, I can't use TempData and Cache (because there are 2 different requests). How to solve it? Use Session? But session is disabled by default in asp.net mvc and I'm afraid to have unexpected behavior of the whole application if I enable it... Global variables are not approved too (because I need to get value of variable for concrete user)

EDIT: workflow is:

  1. client jquery script call Upload method controller and pass a huge file. This method is executing long time (i.e. 1 minute, no matter). This method generates the unique name of file and add record to DB (with this unique name)
  2. user can cancel uploading and click 'cancel'. It calls another server method (i.e. named Cancel), which should remove record from DB (added by Upload method) and remove uploaded file (or uploaded part of this file).

So, in Cancel method I need to know the unique name of file, which is being uploaded. I have to store this name in Upload method in any storage (i.e. Redis, DB etc) and remove from this storage after upload success (or in Cancel method, if Cancel was called)

Upvotes: 0

Views: 1127

Answers (1)

RoteS
RoteS

Reputation: 1455

Then I would suggest to keep the value in a cookie for that user if the data is not to sensitive.

If the data is sensitive you need to store if for example in the cache of the server. There you keep a record per user and then reuse that and discard it after you have done the processing. This works well when you have one instance of the website. When you don't you should look at for example a redis cache, sql server, azure table storage, ...

Upvotes: 2

Related Questions