Is the ASP.NET 4.0 SQL session state mechanism backward-compatible with the ASP.NET 2.0 schema for session state, or should/must we create a separate and distinct session state database for our ASP.NET 4.0 apps?
I’m leaning towards the latter anyway, but the 2.0 database seems to just work, though I’m wondering if there are any substantive differences between the ASPState database schema / procedures between the 2.0 and 4.0 versions of ASP.NET. Thank you.
There was no quick answer on this from anybody, so I did some digging. I generated an
ASPStatedatabase using theaspnet_regsql.exetool from .NET 2.0, and then I did the same thing using the same tool but from .NET 4.0. Then, I generated scripts from each of those resulting SQL Server databases and used a comparison tool to isolate the differences.What I found is: The only material difference between the
ASPStateschema from .NET 2.0 to .NET 4.0 versions is thedbo.DeleteExpiredSessionsstored procedure. That’s the stored procedure called periodically by a SQL Server Agent scheduled job also installed by the tool.Consequently, it would seem that the schema for ASPState 2.0 and ASPState 4.0 are perfectly compatible and so it’s not necessary, from a technical standpoint, to segregate ASP.NET 2.0 and ASP.NET 4.0 session state – but I’ll likely do it anyway.
(This finding was a bit surprising, as ASPState changed a lot from .NET 1.1 to .NET 2.0.)
Details for each version’s changed stored proc:
.NET 2.0 ASPState DeleteExpiredSessions stored procedure:
.NET 4.0 ASPState DeleteExpiredSessions stored procedure:
As for why the above change was necessary, I found the following MSDN blog post:
Excerpt, in reference to the older procedure:
Consequently, the newer version of the stored proc may be advisable for ASP.NET 2.0 apps, too.
One more thing I learned from the blog post that I did not know: ASP.NET 4.0 session state mechanism now offers compression. Search on
compressionEnabledat sessionState Element (ASP.NET Settings Schema).Finally, I also just found something relevant from Microsoft, at ASP.NET Side-by-Side Execution Overview. Excerpt:
(Though there are some differences in implementation not specific to the schema.)