ASP.NET Session State provides three storage options out of the box. They are InProc, StateServer, and SqlServer. But, all three have problems in terms of either slow performance, low or no scalability, and lack of reliability. And, these problems become more severe when your ASP.NET applications run in a load-balanced web farm.
InProc and StateServer do not replicate ASP.NET Session State and therefore cause session data loss in case a server goes down. SqlServer can be replicated through SQL Server clustering but is slow and expensive. All three options have serious scalability issues.
A much better option is to use an in-memory distributed cache like NCache for storing your ASP.NET Session State. NCache provides intelligent replication of ASP.NET Session State and linear scalability at the same time.
NCache is an extremely fast and scalable in-memory distributed cache for .NET applications. It lets you cache application data, reduce those expensive database trips, and improve your application performance and scalability.
If your ASP.NET application is running in a load balanced web farm then you need a scalable and reliable ASP.NET Session State storage. And, NCache is an ideal ASP.NET Session State Provider (SSP) and you should use it for these reasons:
The best thing about using NCache for ASP.NET Session State storage is that there is no programming required on your part. You simply modify your web.config and specify NCache as your Session State Provider (SSP). Here is an example of web.config changes:
<sessionState cookieless="false" regenerateExpiredSessionId="true" mode="Custom" customProvider="NCacheSessionProvider" timeout="20"> <providers> <add name="NCacheSessionProvider" type="Alachisoft.NCache.Web.SessionState.NSessionStoreProvider" useInProc="false" cacheName="myReplicatedCache"/> </providers> </sessionState>
By plugging in NCache ASP.NET Session State Provider (SSP) through web.config changes, you gain an enterprise level in-memory distributed cache for your ASP.NET application. Here are some features NCache provides for ASP.NET Session State:
WAN Replication of ASP.NET Session State: NCache provides a Bridge Topology to allow you to replicate your ASP.NET Session State store (the cache) to other datacenters across the WAN. NCache supports active-passive, active-active, one active and multiple passive, and 3 or more active datacenter scenarios.
In case of active-active scenarios if the same ASP.NET Session State gets updated in multiple datacenters and causes a conflict, NCache does conflict resolution on “last update wins” rule. But, you can provide your own conflict resolution handler.
With NCache Bridge Topology, you can ensure that your ASP.NET Session State is replicated to multiple datacenters and there is no loss of data in case any datacenter goes down. Read more about Bridge Topology.
Multi-site ASP.NET Session State: If you don’t want to replicate ASP.NET Session State across the WAN because of bandwidth consumption cost, you can choose to use this Multi-site ASP.NET Session State feature of NCache. In this, the ASP.NET Session State is not replicated across sites and instead is kept at the location of its creation. But, then it is accessible to your ASP.NET application that is running in other datacenters.
This allows you to have two or more active data centers, keep most of the traffic to its own datacenter but occasionally overflow to the other datacenter if you want. And, you can also bring down one datacenter without causing any interruptions for the users because their sessions will be accessible by other datacenters.
With Dynamic Compact Serialization, NCache provides a way for you to register your .NET classes with NCache and NCache generates serialization source code at runtime when your application connects to the cache. NCache then compiles this source code in memory and uses it for serialization. That is why this is so much faster than regular .NET serialization.
Please see details of all these features on Edition Comparison page. Read more about NCache and download a full working 60-day trial of NCache.