Scenario: In one of the projects, i got a situation where Half of the application is Migrated to MVC and other half is in Old 3 tier architecture.
Now, i have to host both the applications, and need to switch the context from one app to other with out intervening the user actions. We use to save all the user context and other information in sessions to maintain the state.
Bottom line is "I have to share the sessions between two different virtual directories in order to maintain the continuity of the application."
Resolution : After verifying couple of approaches, we found that Session can be shared by using a combination of Custom Http Module and SQL State management. We will see how to do that step by step.
Before going to Actual implementation, we need to see what are the tables used for SQL state management and their significance, thus we can understand how to make them work as we require.
Sql Server State Management: We know what are the different steps to do in order to configure SQL State management. Lets Open and see ASPState database. You will have 2 data tables.
#1. ASPStateTempApplications - This used to create a unique Appid for each in-comming application request based on the unique application name/ application ID.
#2. ASPStateTempSessions - This is used to create unique sessions for each user, correlated with each applicationid created in #1 table.
Logic: Now, from #1, you might have observed if you have 2 different applications, there will be 2 different application ids that will be created in table #1. So our duty is to restrict both the applications to create a single Appid, and this is acheived by using custom HTTP Module.