views:

173

answers:

2

Here is my situation: I will have a web page with TreeView control, which is supposed to be expadable/collapsable/editable. All good so far. I know that postback is used heavily in this control which brings me to another problem that's specific to our production set-up.

We have 2 web servers here and a load balancer, the load balancer doesn't work properly and unfortunately can't guarantee that the page is going to get submitted to the same web server. In other words, a situation may happen when session will not remember who you are or any variables (such as treeview viewstate) saved in session will get lost.

I need to make sure that my treeview always posts back to the same server. My solution was when the page first loaded get the web server's IP adress and rewrite all the links/buttons to point to that IP specifically to bypass the load balancer. The problem arises with the treeview. How do I make sure that it posts back always to the same IP address?

Thanks

A: 

Viewstate is stored in the form, not in a session variable. If you examine the html source for your page, you should see a "_viewstate" hidden form field.

You might try running this on your local machine using Cassini to help isolate the problem.

Also, this is yet another example of why session variables should be avoided. Anything stored in a session can also be stored in a database, which is where it should live.

David Lively
I think the main issue is the fact that he's dealing with a load balanced environment. For all intents and purposes viewstate and session state will pose the same problem in the presence a mis-configured load balancer.
Gurdas Nijor
^ditto. I basically can't save anything on the server, whether it is session, viewstate or whatever else. I basically have no guarantee that my page will be posted back to the same server, hence i can't rely on the server at all.
gnomixa
With a proper set-up session variables can be used just fine. This has been an industry standard for a while now. I think it depends on the scenario - if you need to hit the database every time the page loads, for certain cases this could turn into a big issue. properly configured load balancer and session vars get along just fine together.
gnomixa
A: 

I think the answer here is to remedy the load balancer situation, not hack around it.

First off, just to be clear, Viewstate is entirely form data posted back to the server, so that is not inherently a problem like Session data is. That is, if your servers are set up correctly you can successfully do cross-server postbacks and retain Viewstate. See Jeff Atwood's blog entry about sharing machine keys or disabling Viewstate keying.

For in-proc Session, of course you can't, so that may still be a deal breaker. What you should really do is either:

  • Configure the load balancer to support session affinity so all requests go to the same server
  • Use SQL session or a different state server shared between the web servers
Kurt Schindler
yes, kurt I know it needs to be fixed. Unfortunately though, this is not my responsibility nor expertise, this whole situation is making me very agitated. i am somehow expected to do server side coding without being able to rely on the server.
gnomixa
I know how you feel... I do think you can work around this though if you can get the servers to accept each others viewstate and off load any other session-level data into your own db storage/retrieval.
Kurt Schindler
thanks :) I am told that i can't use the db storage for session as it is a single point of failure. fun eh?
gnomixa