views:

119

answers:

2

Hi all,

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

+1  A: 

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
A: 

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
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
Good point! Right I might have a bash at that this week then. Cheers.
Jamie