ASP.NET MVC CookieTempDataProvider.DeserializeTempData returns null
Asked Answered
W

1

4

I've been trying to use CookieTempDataProvider to pass a basic message between a post (entity update) and a get (entity list) using the RedirectToAction method. When using the default TempData implementation this works fine, however when I use the cookie-based version from the MVC Futures project, the TempData dictionary is empty after the redirect. This is because the TempDataDictionary is returned as null from the DeserializeTempData method. I know exactly what line of code the problem occurs on, and I know how to fix it, but I can't believe that I'm the only one to have this problem.

Maybe I'm using the wrong version of the MVC Futures project, but I've just downloaded the ASP.NET MVC v1.0 source and the problem definitely exists there. Does anyone else use CookieTempDataProvider, and does it work for you?

The problem with the CookieTempDataProvider class, as I see it, is on line 62, where it is casting the deserialized object as TempDataDictionary instead of as IDictionary<string, object>. When I make this change, everything works perfectly.

Anyone else see this problem, or is it just me?

Weiler answered 25/8, 2009 at 7:42 Comment(3)
An update on this: when I run the MVC unit tests, they all pass, but when I use the class in my application, the deserialization works but it does not consider the resulting object to be a TempDataDictionary.Weiler
Further update: When running the unit tests, the object that is passed into the ITempDataProvider.SaveTempData method is a TempDataDictionary, and it is serialized as this. However, when running the MVC app, the object that is passed into the ITempDataProvider.SaveTempDatadata method is an IDictionary<string, object>, and is serialized as a Dictionary<string, object>.Weiler
For anyone interested, this bug is now fixed in MVC 3.Weiler
E
3

Same here. Didn't work after using assembly as is from MVC Futures. Changing line 62 as you suggested fixed the problem. Thanks for posting.

Engineer answered 23/2, 2010 at 3:51 Comment(1)
Yup. MVC 2.0 and bug on line 62 is still 100% intact.(And was causing the exact same problems/issues where TempData wouldn't be intact following a Redirect.)Sweepstakes

© 2022 - 2024 — McMap. All rights reserved.