sapi
sapi

Reputation: 10224

Is storing values in TempData safe for multiple concurrent users?

I've been using TempData to preserve my model in between page requests, as otherwise I lose access to specific properties of classes in the model that I need.

(It's a slight digression and simplification, but basically I have a List of objects which have a .name and a .active property. I have a CheckBoxFor the .active property, and that is preserved, but the .name property is set to null when the form is submitted; I need access to that property as well, so I've been storing the old model in TempData and then copying over that property when I need it. Is there a better way of doing that? I was quite surprised that properties of objects that I'm using would be nulled.)

The model is stored in TempData when the user checks a checkbox, thus submitting the form. It is read out of TempData at some later time, when the user clicks a button. (There are no intervening requests.)

Is using TempData in such a way safe for multiple users? In other words, does each client get its own copy of TempData? I'm worried about a situation roughly like the following:

  1. User 1 clicks checkbox, saving his model to TempData
  2. User 2 clicks checkbox, saving her model to TempData
  3. User 1 clicks button, submitting the form and reading a model from TempData

What I am unsure about is which model User 1 will get. Could someone please enilghten me?

Upvotes: 8

Views: 4779

Answers (1)

Daniel A. White
Daniel A. White

Reputation: 190976

TempData is session bound. User 1 will only see its TempData.

Upvotes: 11

Related Questions