Chong Chang

So you want to build an ASP.NET web application in the Windows Azure cloud? Unfortunately one of the issues you may run into is persisting session state. By default, ASP.NET sessions are configured for InProc or, in other words, stored in memory. If you configured only one instance, you’d be fine. However, this defeats the purpose of running your web application in the cloud. Windows Azure is designed to support a multitenant, scalable architecture. It’s also not a good idea to configure just a single instance because Azure is a stateless, virtualized platform, which means that at any time the instance could be moved or brought down for maintenance (don’t ask me how I know). Running multiple instances means you cannot utilize the traditional InProc configuration because each instance is essentially a separate server participating in a web farm. The servers do not share memory so you have a situation where one server does not have access to the others’ session state.

There are two session state solutions that will work in Windows Azure. Both have their pros and cons.

The first is the SQL Azure Session Provider solution. The details of the implementation can be found here.

Pros:

Cost-effective

Fast, but not as fast as the Windows Azure AppFabricCaching solution

Fairly simple deployment

Cons:

Need to manually or periodically clear unusedsessions

Not officially supported by Microsoft

The second is the Windows Azure AppFabric Cachingsolution. The details of the implementation can be found here.

Pros:

In-memory cache, which results in greatperformance

Officially supported by Microsoft

Simplest deployment of the two solutions

Cons:

Expensive compared to the SQL Azure SessionProvider solution

I’ve implemented both solutions. I prefer the Windows Azure AppFabric solution for three reasons: it provides great performance, Microsoft supports it, and it’s easy to deploy. I understand costs may be a determining factor for your solution. If you have budget constraints, the SQL Azure Session Provider solution would work just as well. If you’ve implemented any of these solutions, please share your opinions below.