使用 SQL Server 和 TempData MVC 进行负载平衡

发布于 2024-09-03 08:44:50 字数 251 浏览 3 评论 0原文

有人告诉我,在使用 SQL Server 时,MVC 1.0 TempData 无法在负载均衡器下工作,这是因为字典本身不可序列化。

我们的项目需要此功能,并且希望能够有效地进行负载平衡。

因此,如果有人能够回答以下问题,我将不胜感激: 有什么办法可以让它发挥作用吗? MVC 2.0 中修复了这个问题吗? 我们可以创建一个 ITempDataProvider 来修复它吗? 或者是否有人修复了他们想要分享的自己项目的源代码?

干杯, 杰米

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甲如呢乙后呢 2024-09-10 08:44:50

字典本身不需要可序列化。您存储在 TempData 中的内容需要可序列化。例如,如果您有以下类,

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

您可以完美地使用 SQL Server 进行会话持久性并编写以下代码:

TempData["foo"] = new Foo { Bar = "bar" };
Session["foo"]  = new Foo { Bar = "bar" };

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" };
尴尬癌患者 2024-09-10 08:44:50

嗯,那么任何 UI 模型 (ASP.Net MVC) 都只需要 Serialized 属性并且应该可以工作吗?

它如何适用于基于列表和集合的 UI 模型?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文