Managing ASP.NET Session State with Windows Azure AppFabric Cache

As has been published on numerous blogs now, Windows Azure AppFabric Cache is now in production and free to use until August 1, 2011. See here for the official announcement:

Now, there is a wonderful sample and video on codeplex ( that simulates how the Session State Management works. However, I don’t like simulations Smile so I took my existing code from this blog post, complete with the “Process ID” indicator that will help me understand which instance is now really serving up my data, and implemented AppFabric Cache using the code snippets provided in the Windows Azure portal.

And it really is that simple – again, all that you need to copy into your web.config is precreated for you in the Windows Azure Management portal, you won’t need to type a single line or even touch any of your code outside of web.config:


BIG Caveat – don’t try this at home!

Now what do I mean with that? What surprised me at first was that the session state caching didn’t seem to be working in my local Compute Emulator. When running this against multiple instances, I got separate session states when hitting other instances. No problem whatsoever running it live in the cloud.

Why is that?

I had already hit this with the SQL Session State provider, so this was quite easy to understand – the Session State providers tend to use the IIS Site Name to identify individual web applications to avoid sharing session state between different apps (which is a very sane thing to do, from a security perspective). And this is where you have a distinct difference between your local compute emulator and a live deployment.

In the production environment, all of your web roles will host your application under the same Site Name on the different instances. In your emulator, on the other hand, all needs to be handled by one IIS Server, so you end up with different Site Names for each instance.

So, in essence, you won’t be able to test session state management with multiple web role instances on your compute emulator.

Comments (3)

  1. thanks for this post. I was wondering why my session state doesnt work locally with the azure emulator. And i will migrate to azure cache soon.

  2. default says:

    Can I have a session management and and variable sharing across appfabric in windows Azure? How's the step by step process

  3. Preetham Reddy says:

    I have 128MB Cache in Azure… How do I clear the session values after it's expired?

Skip to main content