Microsoft Azure provides a platform for ASP.NET applications in the cloud. Very often, these applications are high transaction and mission-critical in nature. Therefore, it is very important that these applications are scalable and result in no data loss if a web server goes down at any time.
ASP.NET Session State Storage Options
ASP.NET Session State needs to be stored somewhere and its storage becomes a major performance and scalability bottleneck. In Microsoft Azure, you can store ASP.NET Session State in InProc, Azure Table, SQL Database, or in a Distributed Cache.
InProc session storage option doesn’t work well in Microsoft Azure architecture. Firstly, ASP.NET Session State is not shared between multiple instances of the Web Role in InProc mode. Secondly, you end up using sticky sessions in Microsoft Azure, which may result in uneven load distribution. Additionally, sticky sessions involve extra configurations on your end as Microsoft Azure doesn’t use sticky sessions by default. Moreover, any Web Role instance going down due to failure or for maintenance will result in session data loss and this is obviously not acceptable.
Azure Table Storage is a file based ASP.NET Session State provider, which is given on an ‘as-is basis’ as a code sample, meaning it is not officially supported by Microsoft. It is intended for storing entities that are structured. Even though it is a cheaper option it is still not an ideal place to store ASP.NET Session State primarily because of performance as it is file-based.
Microsoft Azure SQL Database can also be used as storage for ASP.NET Session State by using the conventional ASP.NET SQL Server Mode. But the ASP.NET Session State object is stored in the database as a BLOB and relational databases were never really designed for BLOB storage. This causes performance issues, and it is definitely a major scalability bottleneck for your Microsoft Azure ASP.NET application.
Distributed Cache provides an ideal storage for ASP.NET Session State in Microsoft Azure. For example, you can use NCache for Azure which is a Microsoft Azure Distributed Cache for .NET applications. It is extremely fast and more scalable than all other Microsoft Azure options mentioned above, and it also replicates sessions so there is no data loss if a cache server ever goes down. Moreover, you eliminate all issues related to session sharing as well as use equal load balancing that ensures full utilization of all of your Azure Web role instances.
Plug-in NCache as your ASP.NET Session State Provider. NCache is an extremely fast and scalable Open-Source distributed cache for .NET. It handles extreme transaction load by allowing you to add more cache servers at runtime and scale linearly. NCache also provides intelligent cache replication so you don’t lose any ASP.NET Session State if a web server or a cache server goes down.
How to Configure NCache in Azure ASP.NET Session State Provider?
NCache in Azure has implemented the ASP.NET Session State provider that can be used by Microsoft Azure ASP.NET applications. NCache in Azure uses Microsoft Azure VMs and formulates a dedicated caching tier. ASP.NET applications in Microsoft Azure can then be directed to use this Azure Distributed Cache for ASP.NET Session State storage.
The highlight of using NCache in Azure ASP.NET Session State provider is that it doesn’t require any application code changes. Its configuration is very easy, just modify your application web.config file as follows to use NCache in Azure as your Distributed Cache for ASP.NET Session State:
<sessionstate cookieless="false" regenerateexpiredsessionid="true" mode="Custom" customprovider="NCacheSessionProvider" timeout="20"></sessionstate>
<add name="NCacheSessionProvider" type="Alachisoft.NCache.Web.SessionState.NSessionStoreProvider" sessionappid="NCacheTest" cachename="TestCache" writeexceptionstoeventlog="false">
NCache in Azure
NCache is an extremely fast and scalable Microsoft Azure distributed cache for .NET applications. NCache in Azure provides intelligent multi-region ASP.NET Session State support for your ASP.NET applications deployed in multiple Microsoft Azure regions.
Here are a few important benefits you achieve when you use NCache for Azure as your distributed cache for storing ASP.NET Session State.
- Linear Scalability and Performance: NCache for Azure is based on dynamic clustering protocol, which allows you to add more servers to your cache at runtime. Your application can scale out linearly by adding more servers to your Azure Distributed Cache when your application load grows without changing application architecture.
- Session Replication: NCache for Azure provides reliability support with help of replication. You can take application instances offline for maintenance, patching, and for new releases without having to worry about any session data loss.
- High Availability: NCache for Azure provides fault tolerant support of high availability as it is based on hundred percent peer to peer architecture. It is guaranteed that you will not lose any data or have any application downtime in case of any node failure from distributed cache.
Azure Distributed Cache such as NCache in Azure is the best option for storing ASP.NET Session State in Microsoft Azure primarily because of performance, scalability, reliability, and high availability features. Microsoft Azure Distributed Cache offered by NCache for Azure is very easy to use and doesn’t require any application code changes.