3

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

Vivek
  • 31
  • 1
  • 2

3 Answers3

8

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
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • I wanted to add that I have made a Session-State provider for Azure that is open source, it can be downloaded from here http://azureproviders.codeplex.com/ –  Jul 18 '11 at 12:50
3

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.

Community
  • 1
  • 1
David Makogon
  • 69,407
  • 21
  • 141
  • 189
1

Select a way for Session Management on Windows Azure

AppFabric Caching service is live now.

Cheers.

Community
  • 1
  • 1
vtortola
  • 34,709
  • 29
  • 161
  • 263