Many high traffic ASP.NET applications in Microsoft Azure are deployed over multiple Microsoft Azure regions in order to handle geographically separated traffic. In these situations, the load balancer always sends traffic to the Microsoft Azure region closest to the user for faster response time.
In this scenario, you may run into a situation where you have to redirect some of your traffic to and from one Microsoft Azure region to another. This may happen because you have too much traffic in one Microsoft Azure region and another region is underutilized. Another reason may be that you need to bring a region down for maintenance.
When you redirect traffic, your users normally lose their ASP.NET sessions because your ASP.NET Session State is not available in the other Microsoft Azure region. And, this is obviously not good. Ideally, you want to redirect traffic without causing any interruptions for your users.
In Microsoft Azure, the only way you can achieve this is if you keep a common ASP.NET Session State storage across multiple Microsoft Azure regions. This allows you to redirect traffic without losing any ASP.NET Session State. But, this option has severe performance issues because a large percentage of ASP.NET sessions are being accessed across the WAN.
NCache in Azure is an extremely fast and scalable Microsoft Azure distributed cache for .NET applications. NCache in Azure provides an intelligent multi-region ASP.NET Session State support for your ASP.NET applications deployed in multiple Microsoft Azure regions.
NCache in Azure intelligently detects and then automatically moves your ASP.NET sessions from one Microsoft Azure region to another region when user request is redirected from one Microsoft Azure region to another. All subsequent requests are served from this new Microsoft Azure region. This allows your ASP.NET applications to seamlessly share ASP.NET sessions across Microsoft Azure regions without negatively impacting performance or causing session data loss.
NCache for Azure allows you to achieve multi-region ASP.NET Session State capability by defining primary and secondary caches in each Microsoft Azure region. Additionally, you also specify “sid-prefix” attribute, which is prefixed to all session-IDs in each Microsoft Azure region. This helps NCache for Azure SSP module to identify which ASP.NET sessions belong to which Microsoft Azure region and then NCache for Azure decides to move ASP.NET sessions when a request redirects to another Microsoft Azure region.
Here is a sample config to use NCache for your ASP.NET Session State storage:
<assemblies> <add assembly="Alachisoft.NCache.SessionStoreProvider, Version=x.x.x.x, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/> </assemblies> <sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="NCacheSessionProvider" timeout="20"> <providers> <add name="NCacheSessionProvider" type="Alachisoft.NCache.Web.SessionState.NSessionStoreProvider" sessionAppId="NCacheTest" cacheName= "London_Cache" writeExceptionsToEventLog="false" /> </providers> </sessionState>
Additionally you need location affinity configurations for Azure Multi-region ASP.NET Session State support.
<configSections> <section name="ncache" type="Alachisoft.NCache.Web.SessionStateManagement.NCacheSection, Alachisoft.NCache.SessionStateManagement, Version=x.x.x.x, Culture=neutral, PublicKeyToken=CFF5926ED6A53769"/> </configSections> <ncache> <sessionLocation> <primaryCache id = "London_Cache" sid-prefix = "LDC"/> <secondaryCache id ="NewYork_Cache" sid-prefix = "NYC"/> <secondaryCache id ="Tokyo_Cache" sid-prefix = "TKC"/> </sessionLocation > </ncache>
Please note that <ncache> section in each Azure Region will be different, meaning each region will have its own “PrimaryCache” and will define all other region caches as “SecondaryCache”.
All ASP.NET sessions originated from any Microsoft Azure region are originally stored in the primary cache in that region. However, when a request from another Microsoft Azure region is redirected to the current Microsoft Azure region then NCache for Azure multi-region SSP module intelligently detects that the ASP.NET Session State resides in one of the other Microsoft Azure regions (using “sid-prefix” attached to ASP.NET Session ID) and it automatically contacts the corresponding secondary cache on remote Microsoft Azure region and moves it to primary cache on current Microsoft Azure region. All subsequent requests are then served from this new location.
Say for example, you have defined London_Cache to be your primary cache while NewYork_Cache and Tokyo_Cache are defined as secondary caches for London site. You also specify “LDC”,”NYC” and “TKC” as sid-prefix that are attached to each session-id corresponding to London_Cache, NewYork_Cache and Tokyo_Cache sessions respectively. Now, all ASP.NET sessions originated from London region have “LDC” attached as prefix to their ASP.NET Session IDs and are stored and served from London_Cache, which is primary cache for London region. But, if a request is redirected from other Microsoft Azure region such as New York or Tokyo to London region then this ASP.NET Session State is immediately identified based on sid-prefix and ASP.NET Session State is transferred from NewYork_Cache or Tokyo_Cache to London_Cache. All subsequent requests are served from London_Cache locally once ASP.NET Session State is moved to London region.
NCache for Azure multi-region ASP.NET Session State support allows you to have your ASP.NET applications deployed in two or more active Microsoft Azure regions and be able to redirect traffic between Microsoft Azure regions without impacting performance or causing any application downtime. You can seamlessly redirect requests between Microsoft Azure regions to handle traffic overflows and site maintenance.