I have an MVC 5 mobile website that I am trying to make a standalone mobile web app running full screen on an iPhone. Everything works well until the app launches an external link that will, for example, launch in Safari. Upon returning to the web app the Session data seems to disappear and a new Session Id is assigned, wiping out any existing trace of previous user progress prior to the external launch. The User Name, however, remains intact and “logged in”. What do I need to do to persist the Session data?
I’ve been at this for hours now, googling and trying different approaches, but to no avail and my head is spinning. A similar post is HERE but my problem is the Session data.
Any help/direction would be greatly appreciated.
UPDATE 1 It seems that this behavior is limited to iOS -- currently testing on 9.3.3. Same behavior whether the "Back to [App] upper left link in the status bar is used or double-tap on the home button to return to WebApp. Android OSs seem to work just fine. Go figure. We are using cookies.
So it was a "Hail-Mary pass" but it worked... just persist the ASP.NET_SessionId cookie in javascript. It may have worked elsewhere but here's what I did:
In _Layout.vbhtml I added this to $(document).ready:
if (window.navigator.standalone || window.matchMedia('(display-mode: standalone)').matches) {
document.cookie = "ASP.NET_SessionId=@(Session.SessionID); " + extendTimeStr(5);
}
along with the function:
function extendTimeStr(extMins) {
var d = new Date();
d.setTime(d.getTime() + (extMins*60*1000));
return "expires="+ d.toUTCString();
}
Magically, it worked! Hope it helps someone.