I have 2 applications running on the same domain. The flow goes like so:
- Application 1
- Application 1 -> Application 2
- Application 2 -> Application 1
Application 1 is WebForms (asp.net framework 2.0), Application 2 is ASP.NET MVC 3 (framework 4.0)
While the user is on Application 2, I'd like to keep the session alive on Application 1.
While building Application 1, we built in a "KeepSessionAlive.ashx" handler that simply does Session("KeepSesssionAlive") = DateTime.Now() when requested, as described in this article. We did this because this is an assessment application and during some of the harder parts of test, a user might need a long time before they choose an answer. Here is the code:
Public Class KeepSessionAlive : Implements IHttpHandler, IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Session("KeepSessionAlive") = DateTime.Now
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Then, I simply call this handler periodically within Application 1
using jQuery:
$.post("KeepSessionAlive.ashx", null, function() { });
So, I figured I could call that same handler from Application 2 using $.ajax(), I even looked into using jsonp, but this doesn't seem to be working. I wrote code to log all the session variables from KeepSessionAlive.ashx to a file, and even to return stuff via jsonp response, and the data looked right.
However, doing a test in which I lingered in Application 2 long enough for Application 1's session to expire and then trying to do the transition from Application 1 -> Application 2, when I reach the return page in Application 1 I'm greeted with an System.NullReferenceException: Object reference not set to an instance of an object.
error because I'm trying to reference one of the objects in Session. The only value in session is Session("KeepSessionAlive"). I assume this is because it created a new session, but if that's the case, why were my tests that logged the session values showing all of Application 1's session variables?
Are there any other methods I can use to keep Application 1's Session alive while the user is filling out the forms in Application 2?