This is related to a gist I wrote for doing this with ASP.NET Core 8, which was a refactor based on this code. I'm just dumping the old code here for reference. Read that gist for full description of the strategy and challenges I had to overcome.
This older version is using ActionFilter on the MVC 5 side of things to coordinate sync and puts a class holding the data and helper methods in the controller's ViewBag with a handy extension method to access it. The new refactor for ASP.NET Core 8 is using a scoped service class you can inject where you need it.
The classicASP side is virtually the same in both versions aside from a few tweaks I did in the newer version to drop an unnecessary HTTP verb and improve sync of removed variables.
If you end up using any of this, my only ask is that you link to this gist and give me some credit in your code for the next developer to discover... and of course tell me about how it saved your life in the gist comments :P
Basically, you will want a subfolder on your website to hold the classic ASP related files. I used /internal
to hold session.asp
, JSON.js
and a custom web.config
with the extra HTTP verbs defined for the classic ASP ISAPI handler.
Add the other files in your MVC 5 project and adjust the namespaces. You will need to edit the fetch URL path in SessionSync.cs
to match where you put session.asp
around line 41.
/Global.asax
/App_Start/FilterConfig.cs
/Extensions/ControllerExtensions.cs
/Extensions/RequestExtensions.cs
/ClassicASP/SessionSync.cs
/ClassicASP/SessionInfo.cs
I'm not getting detailed on it here, but I started with an existing classic ASP website and created an application folder in IIS for the MVC5 website. I added some rewrite rules in web.config to hide the application folder from the URL path for a more seamless experience. I remember having some challenges getting it to work, but it was long enough ago that I can't really explain it more than that. You're on your own on getting the two sites to play nice together :P
If you're looking to get ASP.NET Core 8 and classic ASP working together, I have another gist about how I got that to work. In that case I actually got them to work in the same folder without creating an IIS application folder.
In a Razor View access the session state object in the ViewBag: @ViewBag.ClassicASP["somevariable"]
In a controller you can use an extension method to get a strongly typed reference: this.ClassicASP().MemberName
, or you can get a dynamic reference from the ViewBag: ViewBag.ClassicASP.MemberName
or ViewBag.ClassicASP["member_name"]
.
If you update any values, you can push them back to classic ASP by setting ClassicASP.SaveMode
to SyncMode.Merge
or SyncMode.Replace
. You can also use SyncMode.Clear
or SyncMode.Abandon
to perform those actions on the classic ASP session. These 4 actions are not immediate; they will occur at the end of the request processing.