I want to share data between two async requests to the server.
When some session variable value is changed in the first request (the value is changed continuously) I want the updated values in the second request.
How i should do this?
I want to share data between two async requests to the server.
When some session variable value is changed in the first request (the value is changed continuously) I want the updated values in the second request.
How i should do this?
If the requests are part of the same session, just use the session on the HttpContext. If not, then store the variable in the application context and update/use it from there.
As tvanfosson suggested, it is likely that the browser is caching the results, so you only see the first results over and over, especially if you are using HTTP GET instead of POST. To avoid this, apply this attribute the "progress bar" action:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
Also, unless the "progress bar" action executes on a controller that specifically has read-only access to Session, then it will be forced to wait until the Async action has completed. See Andy's answer to "ASP.NET MVC and Ajax, concurrent requests?". This means that you need to split the progress bar action out to a separate controller that has this attribute applied:
[SessionState(SessionStateBehavior.ReadOnly)]
In summary, your progress bar action will need to look like:
[SessionState(SessionStateBehavior.ReadOnly)]
public class ProgressBarController : Controller
{
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult ProgressBar()
{
var progress = Session["progress"];
return Json(progress, JsonRequestBehavior.AllowGet);
}
}