Note that there are some explanatory texts on larger screens.

plurals
  1. POKeeping a related ASP.NET application's session alive from another ASP.NET application
    text
    copied!<p>I have 2 applications running on the same domain. The flow goes like so:</p> <ol> <li><strong>Application 1</strong></li> <li><strong>Application 1</strong> -> <strong>Application 2</strong></li> <li><strong>Application 2</strong> -> <strong>Application 1</strong></li> </ol> <p><strong>Application 1</strong> is WebForms (asp.net framework 2.0), <strong>Application 2</strong> is ASP.NET MVC 3 (framework 4.0)</p> <p>While the user is on <strong>Application 2</strong>, I'd like to keep the session alive on <strong>Application 1</strong>.</p> <p>While building <strong>Application 1</strong>, we built in a "KeepSessionAlive.ashx" handler that simply does Session("KeepSesssionAlive") = DateTime.Now() when requested, as described in <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=453&amp;AspxAutoDetectCookieSupport=1" rel="noreferrer">this article</a>. 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:</p> <pre><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 </code></pre> <p>Then, I simply call this handler periodically within <code>Application 1</code> using jQuery: <code>$.post("KeepSessionAlive.ashx", null, function() { });</code></p> <p>So, I figured I could call that same handler from <strong>Application 2</strong> 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.</p> <p>However, doing a test in which I lingered in <strong>Application 2</strong> long enough for <strong>Application 1</strong>'s session to expire and then trying to do the transition from <strong>Application 1</strong> -> <strong>Application 2</strong>, when I reach the return page in <strong>Application 1</strong> I'm greeted with an <code>System.NullReferenceException: Object reference not set to an instance of an object.</code> 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 <strong>Application 1</strong>'s session variables? </p> <p>Are there any other methods I can use to keep <strong>Application 1</strong>'s Session alive while the user is filling out the forms in <strong>Application 2</strong>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload