Shared Session State in ASP.NET 1.1

Intro
Synchronized ASP.net Cache
Custom State Server

Intro
“Everything that can be invented has been invented”, only we need careful scrutinizing of the subject and proper googling to find info and to put these pieces together. This approach allows you to save your time, and it works well in my practice.
Recently I was bumped into idea how to replicate ASP.NET 1.1 session state in WebFarm cluster for our project. We need to keep user’s UI settings shared among cluster and provide data integrity for fail-over and fail-back. There are several cases for this – using Session State Server, SQL Server or 3rd part tools.

• Session State Server (standard asp.net 1.1 one) doesn’t guarantee required level of data reliability, because State Server isn’t scalable – there is only one instance per cluster.
• SQL Server and 3rd part tools, like NCache and ScaleOut, were put away due to design constraints.

This brought me to implementation of custom solution to meet our requirements, and googling has been started 🙂 Below I’ll describe several solutions I’ve found.

 

Synchronized ASP.net Cache

The idea of cache replication (shared cache) in clusters was proposed by Peter Bromberg in his article http://www.eggheadcafe.com/articles/20030420.asp
He suggested to create CacheHolder class that will watch the application cache, and fire event on each change of cache that will update all caches in cluster nodes with HttpRequest call.


(click to zoom)

Scrutinizing this approach I’ve found that it doesn’t work if you are working in the EAI environment where several dependencies on the other code and components have a place. (In my case it means that it’s not suitable to change code of existed WebFarm’s sites to support this model)

 

Custom State Server

Working of session state in ASP.NET 1.1 was described in John Papa article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnetsessionstate.asp
where he explained aspect of Session State.

The key idea is “A state provider completely encapsulates the session-state data and communicates with the rest of the world through the methods of the IStateClientManager interface…” – ta-da – we do know what to do to write custom State Server (and what have been done successfully afterwards), just implement a custom class derived from System.Web.SessionState.IStateClientManager interface. Having worked on this idea I found out that I’m on the beaten path. Thanks to Sergey Sorokin who did the same stuff 2 months earlier: http://www.codeproject.com/aspnet/StateHijack.asp

 

Combining this idea with previous one we get reliable and scalable session state based on custom replicable state server. It’s that what I’m working on now.

 

Update: Sergey published his "StateMirror" code on the sourceForge. Great work, man. (Apr-14, 2006)

 

This entry was posted in Articles. Bookmark the permalink.

9 Responses to Shared Session State in ASP.NET 1.1

  1. jolly says:

    Good thinking !

Leave a comment