I have an ASP.NET MVC3 application where my action generates a list of ids that I want to make available to a subsequent AJAX request. This is so that I can run a long process in the background and poll on it. The list of ids are the necessary input to this long running process. I don't want to pass them in the URL as a parameter, because the list could potentially be very long and cause issues in IE.
My Controller
public ActionResult Run()
{
List<MyObjs> objs = _db.MyObjs.ToList<MyObjs>();
string uniqueId = Guid.NewGuid().ToString();
ViewData["UniqueID"] = uniqueId;
TempData["ObjIdList" + uniqueId] = String.Join(",", objs .Select(o => o.ObjID).ToArray<int>());
return View(objs);
}
public void StartProcess(string uid)
{
string ids = TempData["ObjIdList" + id].ToString().Split(',');
...
}
My View
var uniqueId = '@ViewData["UniqueID"]';
$(document).ready(function (event) {
$('#startProcess').click(function () {
$.post("/Scheduler/StartProcess", { uid: uniqueId }, function () {
getStatus();
});
event.preventDefault;
});
});
function getStatus() {
var r = new Date().getTime(); // cache killer for IE
var url = '/Scheduler/GetCurrentProgress/' + uniqueId + "?r=" + r;
$.get(url, function (data) {
if (data != "100") {
$('#status').html(data);
setTimeout(function () { getStatus(); }, 100);
} else {
$('#status').html("Done");
};
});
}
This is working in my intial test, albeit on my laptop with one concurrent user. Is this safe, or is there a better way to pass this data?