0

I've an MVC3 web app which uses the default "in process" session. I've the PRG pattern in place - that is while postback if my modelstate is invalid I store the model in TempData and redirect to the original get action. In the get action I fetch the model data (if it exists) and send to the view. I believe this is one of the basic aspects of MVC.

I've learned that TempData in background is a session variable which is used in the PRG transition. What I need to know is whether it is possible to have a conflict or cross refrencing - if I use something like TempData["model"] in two pages and access the pages simultaneously. Would that overwrite the common data in TempData["model"] or is it safe if I use the same tempdata names in two different pages.

And does it conflict with Session["model"] kind of data? I'm facing some unexpected session data corruption - possibly due to my internal code that resets the session data or something else. Is it possible that session data can corrupt partially? I mean Session["data1"] is ok but Session["data2"] is gone?

My users often use the web app for a long duration causing session timeout. I tried for the ASP.Net session state service for session but that caused performance issues because I store some heavy objects (via serialization) in session. So finally I was back to the original default in proces mode.

Pls share if you've had any similar experiences.

Hemant Tank
  • 1,724
  • 4
  • 28
  • 56
  • 1
    Session is always tempermental due to time constrictions. TempData["model"] should not conflict with your Session["model"], however, TempData can only be used once. ViewBag allows reuse. I have previously had to deal with saving the data of a Session back to the DB and it was infuriating. Normally the best idea is to get your users in and out fast rather than let them wander off mid-way through a process. Just a thought. – IyaTaisho Mar 13 '13 at 18:14
  • can you share some relevant code? why you need to store data in TemData and pass it along to GET action? you can simply add model error and return it to the view... – Rafay Mar 13 '13 at 19:19
  • The PRG pattern is required because I don't want to duplicate code like dropdown data source, authentication, etc... My usage of TempData is limited during the redirection to the get request. My code has some other things that might off track. I just wanted to know if TempData can malfunction in case of two parallel requests. – Hemant Tank Mar 14 '13 at 09:10

1 Answers1

0

TempData by default uses SessionState and access to SessionState is by default exclusive. So, if you do two concurrent reuquests, one will have to wait for the other to release the SessionState lock. TempData does not interfere with using SessionState directly. As SessionState by default uses in-proc, it can be invalidated almost anytime.

You might want to have a look at http://brockallen.com/2012/06/11/cookie-based-tempdata-provider/

twomm
  • 551
  • 5
  • 16