开发者

Can I enable and disable sticky sessions on a load balancer from the website behind it?

开发者 https://www.devze.com 2023-01-13 13:35 出处:网络
My challenge is the following. I\'d like to uphold the Post/Redirect/Get pattern for posted forms, but after the redirect I still want to show the state of the form in case of invalid fields. This inf

My challenge is the following. I'd like to uphold the Post/Redirect/Get pattern for posted forms, but after the redirect I still want to show the state of the form in case of invalid fields. This information can be passed by storing it in session quite easily.

However these sites usually run on multiple webservers behind a loa开发者_如何学Cd balancer, which are configured NOT to be sticky. There is also no shared session state on purpose.

To use local session state on the webservers would be preferrable for scalability, but to do that you need sticky sessions. Sticky sessions are however a hindrance to the people who manage the servers, because after removing some servers from the load balancer to do a release, they still have to wait some 10 to 15 minutes before all sessions have ended. Without stickiness it's almost instantaneously.

What would be really cool is if we could make the session sticky for just one single subsequent request after a POST or REDIRECT. Or even have total control over when to enable or disable stickiness from code.

Does anyone know if this behaviour is possible? By settings a certain cookie perhaps? Or some http header?


Few ideas:

  1. Central cache server

    • save it to a cache server (prefered redis) with expiration
    • redirect to the get action with a parameter in the url. Using this parameter restore the model.
  2. State in the url

    • if the model is small You can save it as parameters in the url.
0

精彩评论

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