开发者

Load Balancing using SQL Server and TempData MVC

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开发者_StackOverflow 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


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" };


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜