0

I recently learned that TempData for MVC is backed by Sessions by default, which is a terrible idea if one ever intends to have a web farm...

I attempted to implement Brock Allen's Cookie based TempData provider, however, The ViewData object itself is not marked Seriablizable, and as such, cannot be stored in the Cookie Based provider (or Session State Service, etc etc...)

Type 'System.Web.Mvc.ViewDataDictionary' in Assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.

BrockAllen.CookieTempData.CookieTempDataProvider.SaveTempData(ControllerContext controllerContext, IDictionary`2 values) in c:\ballen\github\CookieTempData\45\BrockAllen.CookieTempData\CookieTempDataProvider.cs:31

System.Web.Mvc.TempDataDictionary.Save(ControllerContext controllerContext, ITempDataProvider tempDataProvider) +154

How do I get around this?!

Update:

Perhaps a batter way to ask this would be: how do I send ViewData to another Controller method (PRG: Post, Redirect, Get paradigm) WITHOUT needing TempData (and therefore Sessions)?

Novox
  • 774
  • 2
  • 7
  • 24
  • Have you considered using farm-friendly session providers (like SqlServer or ASP.NET Session State Server)? – Novakov Jun 24 '14 at 18:30
  • ViewData in MVC, correct. No, I haven't considered using any farm-friendly providers, I'm trying to remove Session dependency completely, and I thought I had until I learned that TempData uses Sessions explicitly... Even Session State Service would require the objects to be serializable :( – Novox Jun 24 '14 at 18:33
  • It says in your header `viewState`. Which obviously don't belong to MVC. `App Fabric` is great idea when you have a web farm – T.S. Jun 24 '14 at 18:37
  • I apologize, fixing title... – Novox Jun 24 '14 at 18:41
  • If you want to share some state (using cookies, state server or anything else) between machines, state need to be serializable – Novakov Jun 24 '14 at 18:46
  • I agree, however, ViewDataDictionary is not serializable... `Type 'System.Web.Mvc.ViewDataDictionary' in Assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.` – Novox Jun 24 '14 at 18:47

0 Answers0