Client Pay Portal

Using Windows Azure AppFabric for Session

Along with Windows Azure’s many features is the AppFrabic. A collection of technologies and systems that expose functionality for communication, messaging, connectivity, and caching, the AppFabric is an excellent solution for storing session info for Windows Azure applications.

To use Windows Azure for session, simply do the following:

1. Create a cache in your Windows Azure Account

The first step to using the AppFabric for session storage is to create a cache container for your data. This is a pretty straight forward process to create. For starters, you can choose the 128MB option to limit the monthly charges until you can determine how much cache your application will use.

2. Update your web.config

After creating your cache, you can click ”View Client Configuration“ in the Azure portal to get the configuration values to use in your application. Be sure to add the section as well as the section.

Client Configuration

<!-- Cache exposes two endpoints: one simple and other SSL endpoint. Choose the appropriate endpoint depending on your security needs. -->
     <dataCacheClient name= "default ">
         <host name= "[YOUR CACHE NAME] " cachePort= "22233 "/>
       <securityProperties mode= "Message ">
         <messageSecurity authorizationInfo= "[YOUR AUTH KEY] "/>
     <dataCacheClient name= "SslEndpoint ">
         <host name= "[YOUR CACHE NAME] " cachePort= "22243 "/>
       <securityProperties mode= "Message " sslEnabled= "true ">
         <messageSecurity authorizationInfo= "[YOUR AUTH KEY] "/>
     <!-- If session state needs to be saved in the Caching service, add the following to web.config inside system.web. If SSL is required, then change dataCacheClientName to "SslEndpoint". --> 
     <sessionState mode= "Custom " customProvider= "AppFabricCacheSessionStoreProvider "> 
         <add name= "AppFabricCacheSessionStoreProvider " type= "Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache " cacheName= "default " useBlobMode= "true " dataCacheClientName= "default "/> 

3. Make sure you are reading / writing to session correctly

Most .NET applications already write to session correctly, but it’s worth noting that you should check your code to make sure. The following is an example of how you should be reading / writing to session:
 HttpContext .Current.Session["YOUR SESSION KEY" ] = "YOUR VALUE" ;

4. Test you application

Once your application is configured to use the cache, be sure to check your code to make sure it is reading and writing properly. You will want to deploy your application to at least 2 Azure instances and then access site. The simplest way to do this is to create a “secure area” of your site that requires a login and then confirm you stay logged in while navigating the site.

With this simple update you can utilize the AppFabric feature to maintain cache for the .NET applications. It’s a nice solution to a problem many companies will face as they migrate applications to Windows Azure. Good luck!


Wiz E. Wig, Mascot & Director of Magic
Wiz E. Wig

Director of Magic