asp.net mvc and web farm

1.9k views Asked by At

given the nature of the project, I need to store a simple object (with 3/4 properties) in TempData. It is a read once write once so that's fine but does need to be passed between a few core methods/actions.

question is: How can I make it work with webfarms? What things are needed to be configured to allow TempData to work with a webfarm?

using MVC 4 Razor.

thank you

2

There are 2 answers

4
Andy T On

By default, TempData is implemented using Sessions, so this would be a problem on a farm.

The easiest solution would be to use the CookieTempDataProvider

0
Wbmstrmjb On

TempData is stored in the session. This means that the only reliable way to use it in a web farm would be to have a state server of some sort.

Changing the ApplicationId (MachineKey) on all the servers to make them match does nothing for session. That only means that each server can decode the cookies left by the others. Session lives on the individual web server in memory.

If you don't have sticky sessions on your load balancer, the request that populates TempData on server 1, will likely redirect to a server different than itself and TempData will not be populated (or not with the same data that was just put in on server 1).