Reputation: 1078
I am storing a "last login" in a Session variable. After performing a "return Redirect(url)", that Session variable is lost. However when I do another "Redirect(url)", I get the session back! Why? I can't have my French page NOT display the last login.
Steps:
Upvotes: 2
Views: 1159
Reputation: 3538
Session, by default, is stored in memory on your server. If I had to hazard a guess, you have more than one instance of your Azure application deployed, but only one of them has your session state. Since Azure's load balancing is round-robin, you'll see your state on roughly every other request if you have two instances.
So given your example above, my comments added:
English page -> shows session variable # Hits IN_0, has session state
Switch to French: Redirect() # Browser makes new request
French page -> missing session variable # Hits IN_1, does not have session state
Switch to English: Redirect() # Browser makes new request
English page -> shows session variable # Hits IN_0, has session state
If you're hosting your site on Azure and intend to use more than one instance, you need to design for the possibility that your user's request may be received by any of those instances.
As for solutions, Azure provides a session state provider that will write your session out to a shared cache rather than storing it in memory. Take a look at http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx for details on how to set that up.
If that doesn't meet your needs, you may want to consider using cookies or persistent storage to store your data instead of the session.
Upvotes: 2