MVC 3 临时数据容器的缺点
虽然问题标题看起来有点主观,但我确信没有太多可讨论的。我目前正在开发一个 MVC 项目,在某些区域使用 TemData 容器。当我阅读 MSDN 中的文档时,似乎使用 TempData 创建了一个会话,并且一旦读取我们存储在 tempdata 中的数据就消失了。我对这个概念很满意,但是今天早上一直困扰我的是,当您在 Web Farm 环境中托管应用程序时,它会如何表现。
如果将 GET 请求传递到 SERVER 1,它创建一个 TempData,然后将后续的 GET/POST 请求发送到 SERVER 2,会怎么样。
我的这个假设可能完全错误,但我只需要对此进行澄清。
任何意见都将受到深深的赞赏...
干杯!
Although the question title appears a bit subjective I am sure there is not a lot to discuss. I am currently working on a MVC project where I am using TemData container in some areas. When I read the documentation in MSDN, it appears that using TempData creates a session and that once read the data we store in tempdata is gone. I am OK with this concept, however the thing that kept bugging me this morning is that how does it behave when you host your application in a Web Farm environment.
What if a GET request is passed to SERVER 1, which creates a TempData and the subsequent GET/POST request is sent to SERVER 2.
I might be completely wrong with this assumption but I just need a clarification on this thinggy.
Any input will be deeply appreciated...
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一些研究后,如果您在应用程序中使用会话变量,我在问题中发布的场景是不可避免的。我们能做的最好的事情就是减少会话中可以存储的数据量,除此之外,如果我们仍然需要在 webfarm/多服务器环境中使用会话,则可以进行一些配置更改。这是一篇关于如何管理会话存储的非常有用的文章。
ASP .NET 会话如何常见问题解答
After doing some research, the scenario that I've posted in my question is inevitable if you use Session variables in your applications. The best thing we could do is to reduce the amount of data that we could store in a session, besides this if we still need to use sessions in a webfarm/multi server environment, there are some configuration changes that one can make. Here is a very useful article on how session storage can be managed.
ASP.NET Session how to FAQs
是的,默认情况下 ASP.NET MVC 将 TempData 存储在会话中。如果会话是 inproc(默认)并且您位于网络场中,那么您可能无法获得下一个请求的正确会话数据。如果您使用 Web 表单,则使用其他会话存储方法,例如状态服务器或 sql 服务器。
Yes, by default ASP.NET MVC store TempData in session. If session is inproc (default) and you are in web farm then you may not get the correct session data for the next request. If you are in web form then use other session storage method like state server or sql server.