I am running in an issue similar to the one in this other thread and I'm getting short of ideas so I would really appreciate any help !
Here's the thing : We have an ASP application that uses session variables and has to deal with session merging due to multitabs (IE8).
After many many many tries, I've came to the following implementation :
I'm setting an ID to each browser's TAB (I'm using the sessionStorage for that) on client-side.
In order to make it available from server-side (since I could not find any other way) I'm saving it in a cookie and reloading the page.
Finally on my ASP pages, I'm getting this ID from the cookie and using it as prefix of all the sessions variables on the application.
Here's a short example
Javascript (Inserted at the very beginning of every asp files)
LoadJs();
// Cookie and TabID handler
function LoadJs()
{
if (getInternetExplorerVersion() <= 6)
{
//alert("Exit..... old browser version : " + getInternetExplorerVersion());
return;
}
if (sessionStorage.TabID)
{
// Check value in cookie
var tabIdinCookie = readCookie("tabid");
// if ID in cookie not the same as ID in session update cookie and
// refresh the page to update values in server-side
if(!tabIdinCookie || (tabIdinCookie && tabIdinCookie != sessionStorage.TabID))
{
createCookie("tabid",sessionStorage.TabID);
ReloadPage();
}
}
else
{
// Create random ID
var currentTime = new Date();
sessionStorage.TabID = currentTime.getTime();
开发者_StackOverflow // Save ID to cookie
createCookie("tabid",sessionStorage.TabID);
createCookie("usingIE8",true,1);
// Refresh the page to make it available from server-side
ReloadPage();
}
return true;
}
// Redirect to the same page to refresh data at server-side
function ReloadPage()
{
window.location.reload(true);
}
Then, the ASP code :
<%
Dim Nm
Nm=""
response.Write("<br>Reading from cookie....")
if (Request.cookies("usingIE8") <> "" )then
if (Request.cookies("tabid") = "") then
'response.Write("<br>No cookie")
'response.flush()
' WHAT TO DO HERE ????
else
Response.Write("<br>Cookie FOUND<br>")
Nm = Request.cookies("tabid")
end if
end if
if (Session(Nm + "LogonTime")="") then
Response.Write("<br><b>Updating session</b><br>")
Session(Nm + "LogonTime") = Now
UpdateInDB(Session(Nm + "LogonTime"))
' Do other stuffs
end if
%>
I was pretty proud about finally getting a workaround to the issue, but I realized that when a page do a post action, all code ASP is rendered (with the wrong prefix-ID) and executed (database operations included) before right TabID can be updated on the cookie and page can be reloaded by javascript. I mean that all my page code is being executed twice, once before and once again after the refresh... :-|
Does anyone think it could be possible to implement smthg like a Response.End() to prevent the rest of the code ASP to execute if I can identify I have to refresh the page without killing at the same time the javascript execution ? Or to wait for all javascript execution before any other action on the page ?
I'm stuck here and it make me cry to have to stop here ! There must be a solution... If I can fin a fix, it would be to be applied to many ASP (3.0) applications that won't be upgraded to ASP.NET before at least 3 or 5 years.
Thanks in advance,
i do not get why you all do this but instead of reloading a whole page i would use ajax to set the session variables?
ok for example with jquery:
// AJAX Request
$.post("session.asp", { act: "setSession", varName: "myVar", varValue: "myVal" },
function(data) {
alert("new Session value: " + data);
});
then on session.asp:
if request.form("act") = "setSession" then
session(request.form("varName")) = request.form("varValue")
' now you have the new value in Session:
'
response.write Session("myVar")
end if
hope this helps
精彩评论