Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does TempData get stored?

Where does TempData get stored in the ASP.NET MVC Framework (more specifically, ASP.NET MVC 2)? Is it stored at server-side, or is sent to the client?

like image 710
Guillermo Gutiérrez Avatar asked Feb 21 '13 13:02

Guillermo Gutiérrez


People also ask

Is TempData private to a user?

Yes, Tempdata is private to a user.

Where ViewData is stored in MVC?

ViewDataDictionary class inherits from IDictionary<string, object> interface and ViewData returns ViewDataDictionary class object, that means ViewData is a collection of Dictionary objects with string, object types. ViewData's data can be accessed in the current page instance.


2 Answers

By default TempData uses the ASP.NET Session as storage. So it is stored on the server (InProc is the default). But you could define other ASP.NET Session state modes: StateServer and SqlServer. You could also write a custom TempData provider and handle the storage yourself if you don't want to use the ASP.NET Session.

like image 64
Darin Dimitrov Avatar answered Oct 05 '22 04:10

Darin Dimitrov


It is stored in session storage, but there is one crucial difference between TempData and Session:

TempData is available only for a user’s session, so it persists only till we have read it and gets cleared at the end of an HTTP Request.

A scenario that fits the usage of TempData, is when data needs to persist between two requests – a redirect scenario. Another scenario I can think of is to return an error message after a POST operation fails.

like image 42
mattytommo Avatar answered Oct 05 '22 05:10

mattytommo