Question

I read that when using Session objects in an ASP.NET web app hosted in Azure, if the request is handled by a different (virtual) machine, the app cannot see Session variables of another virtual machine (obviously), so it is recommended to use Azure Caching Service.

Just to understand:

can these 'virtual machine switches' happen in 'normal' web sites too?

I mean: if I don't configure redundancy (i.e. multiple instances) do I have the risk to 'not see' session variables just the same?

Thanks in advance.

AB

Était-ce utile?

La solution

If you are using Azure Web Sites with a single instance, then you can technically use in-process session storage since all requests are handled by the same instance. Even when using multiple instances in Azure Web Sites, the default behaviour is to use ARR with "sticky" load-balancing, so that all requests for a particular client are routed to the same instance.

However, there are still times when all in-process session data may be lost. If an instance fails, then the site will be quickly transferred to another instance, and any in-memory (or on-disk) data will be lost. For that reason it is better to use some form of separate, persistent storage such as caching, table storage or a SQL database for your session data if it is in any way essential. I believe all the ASP.NET session providers maintain an in-process cache of the underlying store for performance reasons anyway.

If you are using a Cloud Service to run your site, then all requests are load-balanced between all available instances, so separate session storage is essential.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top