How does windows azure websites handle session? How does windows azure websites handle session? azure azure

How does windows azure websites handle session?


If you'd like to learn more about the architecture of Windows Azure Web Sites, I would suggest watching this session from TechEd 2012 Windows Azure Web Sites: Under the Hood


You have some options to solve this problem

  1. sql solution

  2. table storage solution

  3. memcache solution

Sql is the classic solution. Sql handles all sessions with classic sql requests.

Table storage works wonders (in my experience). It's really easy to scale and really simple to implement (just a few lines of code on your webconfig).

Memcache solution is the best solution. Azure provides a cluster of "cache servers" to store session (or other serializable objects). It's really easy to scale and works really really fast. I am using this solution on my production environments with 0 problems and a really good performance results.

In order to implement Memcache, you just need to add those lines on your web.config:

<configuration>    <configSections>                <section name="dataCacheClients" type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" allowLocation="true" allowDefinition="Everywhere"/>        <!-- more config sections here -->    </configSections>    <dataCacheClients>    <dataCacheClient name="default">        <hosts>        <host name="YOUR_NAME_HERE.cache.windows.net" cachePort="YOUR_PORT_HERE"/>        </hosts>    <securityProperties mode="Message">            <messageSecurity authorizationInfo="YOUR_KEY_HERE">                            </messageSecurity>            </securityProperties>    </dataCacheClient></dataCacheClients><!-- more configurations here -->

Summary

If you don't care about the costs and you wish to archieve best performance possible, go for memcache solution. If you need to keep your costs really low, go for table storage.


Since the linked video above is quite out of date, I thought I would share what I was able to find regarding sessions on Azure.

Azure makes use of Application Request Routing.

ARR cleverly keeps track of connecting users by giving them a special cookie (known as an affinity cookie), which allows it to know, upon subsequent requests, to which server instance they were talking to. This way, we can be sure that once a client establishes a session with a specific server instance, it will keep talking to the same server as long as his session is active.

Reference:https://azure.microsoft.com/en-us/blog/disabling-arrs-instance-affinity-in-windows-azure-web-sites/.