Download NCache Now!
Contact Us
Live Chat

ASP.NET Session State Storage in Web Farms

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.

Why Use NCache as ASP.NET Session State Storage in Web Farms?

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:

  • NCache is extremely fast: NCache is an extremely fast in-memory ASP.NET Session State storage option and gives you sub-millisecond response times.
  • NCache provides linear scalability: NCache never becomes a scalability bottleneck. It lets you add servers to the cache cluster to achieve linear scalability and handle extreme transaction loads.
  • Cache size can grow infinitely: NCache provides cache partitioning and pools memory of all cache servers together for it. So, you can grow cache storage by simply adding more servers to the cache cluster.
  • NCache replicates ASP.NET Session State: NCache lets you intelligently replicate sessions across multiple servers and without compromising performance. So, you won't lose any session data even if a cache server goes down.
  • NCache gives you 100% uptime: NCache has a self healing dynamic cache cluster with no single point of failure. As a result, NCache allows you to add or remove cache servers at runtime without stopping your application or the cache.

Use NCache as ASP.NET Session State Provider without Programming

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" 
     <add name="NCacheSessionProvider" 
          useInProc="false" cacheName="myReplicatedCache"/>        

NCache Extra Features for ASP.NET Session State Storage

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:

  1. 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.

  2. 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.

  3. ASP.NET Session State Locking: NCache implements session locking to allow you to handle concurrent ASP.NET Session State access. This may happen if you’re using AJAX or scripts/robots to talk to your ASP.NET application.
  4. App Domain Level ASP.NET Session State: NCache lets you specify that whether you want to keep the same ASP.NET Session State across multiple app domains if the session-id is the same or not. If not then despite having the same session-id, NCache maintains separate ASP.NET Session State for each app domain. Otherwise, the same ASP.NET Session State is shared across app domains.
  5. Faster Dynamic Compact Serialization: When you put your .NET objects in ASP.NET Session State and store it out-of-process (StateServer, SqlServer, or NCache), the entire ASP.NET Session State must be serialized along with your .NET objects with regular .NET serialization. And, this regular .NET serialization uses .NET Reflection at runtime and is therefore quite slow. NCache provides almost 10 times faster serialization called Dynamic Compact Serialization. With this, your ASP.NET application speed increases noticeably. And, the best thing is that you don’t have to write any code for it.

    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.

What to Do Next?