3
votes

I have my site (ASP.Net 4.0 C#) hosted on Azure server with multiple instances. My session state mode is "InProc". Somehow its not working on Azure instances, it doesn't maintain the state properly. Please advice.

Regards Vivek

3

3 Answers

8
votes

If you have multiple instances and are using InProc session, then Session data will not work - as it won't be shared across the instances.

Azure load balances your HTTP requests and may send each client HTTP request to a different server instance.

If you want to use Session state, then you need to use a shared session state provider, such as:

  • the SQL Session State provider (although I believe this has some limitations on SQL Azure as it cannot use the SQLAgent code to periodically clear the state)
  • the demonstration Azure Table Session State provider (not officially supported and sometimes reported as buggy)
  • the latest AppFabric Session state provider (currently recommended by MS) - see http://appfabricdemos.codeplex.com/releases/view/65427
3
votes

Adding to Stuart's answer: The AppFabric Cache is caching-as-a-service, agnostic of any virtual machine instances. This service went live a few weeks ago. The AppFabric team provides a session state provider that uses the cache, requiring only a simple web.config copy-n-paste.

Because of the reasons Stuart mentioned, I wouldn't depend on SQL Azure or Table Storage for your session cache.

There's a good hands-on lab in the Windows Azure Platform Training Kit called Building Windows Azure Applications with the Caching Service - I'd go through that, as one of the topics is configuring session state using the AppFabric Cache.

I provided a bit more info in this SO answer.

1
votes