Sharing Data between Classic ASP and ASP.NET Using Distributed Caching

This sample demonstrates sharing sessions between classic ASP and ASP.NET applications using COM+ interoperability and .NET framework. This allows faster conversion of existing ASP applications into ASP.NET applications module by module in incremental iterations while running the classic ASP and the converted ASP.NET portions of your web application side by side.

Conceptual overview:

The session object for ASP and ASP.NET originates from a common base – a hash table implementation in .NET exposing its functionality to classis ASP through .NET interoperability classes. The classic ASP applications makes use of a COM+ component (written in Visual Basic) to indirectly consume this .NET session whereas the ASP.NET application uses it directly. For Web Farm level Session sharing, these user sessions can be stored in an out-of-process in-memory distributed cache using NCache which gives high performance and scalability. Sessions are identified across both applications using the same Session Cookie. So, when a HTTP request arrives at classic ASP page or ASP.NET page, the session object is retrieved from the distributed cache based on session id contained in the HTTP Cookie and at the end of the response the latest copy of Session is again updated in the Cache.

Implementation overview:

There are four major components: ASP.NET sample app, .NET session module, ASP sample pages and the COM+ component.

ASP.NET Implementation: It contains a single ASP.NET page and a .NET class library for demonstrating custom session state object. The DotNetSession class implements a serializable hash table based session object which is responsible for maintaining the session data. The IDotNetSessionFactory interface represents the functionality needed to load and save sessions in the distributed cache NCache and DotNetSessionFactory class implements this interface.

Whenever a new Session request comes, a new Session Id is generated by calling the method DotNetSessionFactory. GenerateSessionId() that generates a new GUID prefrixed with the appliction id which, in our case, is common for both applications. The DotNetSessionFactory class is consumed from both ASP.NET application and the classic ASP so that both can store and retrieve sessions from NCache. BaseSessionPage class serves as the base class for all ASP.NET pages and it encapsulates DotNetSession object.

The ASP.NET application contains Default.aspx page which inherits from BaseSessionPage and hence provides our custom session state object to this page.

Classic ASP implementation: The COM+ (Visual Basic 6.0) component implements COMSession class which consumes calls to DotNetSession and DotNetSessionFactory classes (implemented in the .NET session module) to generate, save or load sessions from the NCache. For convenience, the SessionInclude.asp page instantiate the COM+ component and is included in every ASP page. SamplePage.asp uses the COMSession class by including SessionInclude.asp and displays the session data and Cookie.

Testing Session Sharing between Class ASP and ASP.NET

The ASP.NET applications provides a default.aspx page and classic ASP provides SamplePage.asp and both these pages creates a new Session if the session is not already created (either by itself or by the other application) and then shows the Session Data and Cookie on the page. These counters together with the session id are useful to track and verify that the same session is being used when you switch from SamplePage.asp to Default.aspx or vice versa.

Quick Details
File Name:
NCache Version 3.8 SP2/3.6.2 SP2
.NET Framework .NET 4.0/3.5/2.0
Date Published: 2010-11-11
Size: 60 KB