0

I've been told that MVC 1.0 TempData does not work under a load balancer when using SQL Server and that it is because the Dictionary itself is not serializable.

We require this for a project and are looking to be able load balancer effectively.

So I would be very grateful if someone could answer the following questions: Is there away around this so you can make it work? Is this fixed in MVC 2.0? Can we create a ITempDataProvider to fix it? Or has anyone made a fix to the source code for a project of their own they would like to share?

Cheers, Jamie

Roman
  • 19,581
  • 6
  • 68
  • 84
Jamie
  • 1
  • 1

2 Answers2

2

The dictionary itself doesn't need to be serializable. It is what you store inside TempData that needs to be serializable. So for example if you have the following class

[Serializable]
public class Foo
{
    public string Bar { get; set; }
}

You can perfectly fine use SQL server for session persistence and write the following code:

TempData["foo"] = new Foo { Bar = "bar" };
Session["foo"]  = new Foo { Bar = "bar" };
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Mmmm, so any UI model (ASP.Net MVC) would just require the Serializable attribute and that should just work?

How does it work for lists and collection based UI models?

Jamie
  • 1
  • The generic collection classes are serializeable as long as the type they are storing can be serialized. (Note that normally you will want to add a comment or edit your question rather than add an answer.) – GalacticCowboy May 27 '10 at 19:25
  • Good point! Right I might have a bash at that this week then. Cheers. – Jamie May 28 '10 at 08:07