簡體   English   中英

如何使“支持 apple-mobile-web-app-capable”的 session 不丟失?

[英]How do I make "apple-mobile-web-app-capable" not lose its session?

我有一個 web 應用程序。

<meta name="apple-mobile-web-app-capable" content="yes">

我把這個放在那里。

我添加到主屏幕。

但是,我意識到在關閉 web 應用程序后,我總是需要重新登錄。

如何讓它保留 session?

有一個簡單的答案,但到目前為止我無法在 Apple 的官方文檔中找到任何參考資料。

訣竅是這樣做:

// Start or resume session
session_start(); 

// Extend cookie life time by an amount of your liking
$cookieLifetime = 365 * 24 * 60 * 60; // A year in seconds
setcookie(session_name(),session_id(),time()+$cookieLifetime);

如果您像這樣延長 session cookie 的生命周期,Safari 將保留 session cookie,甚至允許在 web 應用程序的“主屏幕安裝”版本和通過 883786785555588 本身的正常訪問之間共享 session

如需更詳細的討論,請查看我對這個問題的回答:

在iPhone web app中維護PHP Session

當我必須訪問外部應用程序時,我使用 static class 和 static 變量(如字典(字符串,對象))來保存數據。 如果你使用 FormAuthentication,你會注意到

User.Identity.IsAuthenticated = true 

但 session 不存在。 您可以使用“User.Identity.Name”作為鍵來獲取字典中的數據。

這適用於 ASP.Net MVC3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM