After a few window.open calls my ASP.NET session t

2019-04-11 10:00发布

问题:

I have an ASP.NET application that uses StateServer session mode with cookieless set to false. In a few places, there is a link that pops up a window to another application (which happens to reside on the same domain, but in a different virtual directory). The following steps give me grief...

  1. Launch popup
  2. Close popup
  3. Launch popup to same app as before with a couple different parameters
  4. Close popup
  5. Next request = session timeout on the "parent" window.

Using cookieless sessions fixes the problem, so somehow my cookie is getting whiped out by the browser. Aside from using cookieless sessions, how can this be resolved? For what it's worth, I am developing/testing with IE8.

EDIT

It seems the problem only occurs when the popup resides on the same domain. If I popup a page elsewhere, there is no problem.

回答1:

Is it possible the other app (on the same domain) is setting its own cookie, overwriting that of your primary app? Can you use fiddler (or similar tool) to see which cookies are being set by which apps?



回答2:

Check all instances of your

Session.Clear();
Session.Abandon();

If you aren't using those at all, then its likely the case that your browser windows are set to NOT share sessions between. So the new instance gets a NEW session cookie (since its the same cookie name as the prior one, it could possibly kill the existing session cookie)- as in a play on: http://geekswithblogs.net/ranganh/archive/2009/04/17/asp.net-session-state-shared-between-ie-tabs-and-ie8.aspx

Ideally track down in which page the Set-Cookie header is coming across. Look then at the request going INTO that response and see if your current ASP.NET_SESSIONID cookie is sent over. (fiddler is indeed the best tool for this) Anyway - its a start to try.



回答3:

edit Apparently it's not your cookie name, so... Perhaps you should have an AJAX call on your master page that pings a service (or generic handler) on your web app to keep the session alive.

JavaScript

window.setInterval(function() { 
    $.get('ping.ashx?nocache=' + (new Date()).getTime(), function() { 
        return true; 
    })
}, 30000);

In the Generic Handler, make sure to add the IRequiresSessionState marker interface.

Perhaps your session cookie names are the same.

In your web.config (for one of the applications) change the session cookie name.

<sessionState
mode="StateServer"
timeout="20"
cookieName="DifferentASP.NET_SessionId"