【发布时间】:2012-09-16 06:34:02
【问题描述】:
我在移动 Safari iOS 6 中通过 AJAX 设置会话变量时遇到问题。我提供了一个示例,该示例将设置会话变量、重定向到另一个页面、放弃会话并重新开始。这在前 2 次运行良好。在第三次通过该过程时,会话变量会丢失。该问题仅发生在 iOS 6 Safari 中。它适用于我尝试过的所有其他浏览器。
示例由 3 页组成。 Page1 设置会话变量并重定向到第 2 页。第 2 页显示会话变量。第 3 页放弃了会话变量。
第 1 页 HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true">
<Scripts>
<asp:ScriptReference Path="~/Page1.js" />
</Scripts>
</asp:ScriptManager>
<div onclick="setSessionVariable()">Set session variable and redirect to page 2</div>
</form>
</body>
</html>
第 1 页 Javascript:
function setSessionVariable() {
PageMethods.SetSessionVariable(displaySetSessionVariable);
}
function displaySetSessionVariable(bReturn) {
window.location = "Page2.aspx";
}
第 1 页代码:
using System.Web.Services;
namespace SafariSessionProblem {
public partial class Page1 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
[WebMethod]
public static Boolean SetSessionVariable() {
System.Web.HttpContext.Current.Session["TestVariable"] = 1;
return true;
}
}
}
第 2 页 HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lbl" runat="server" Text="Label"></asp:Label><br /><br />
<div onclick="window.location = 'Page3.aspx'">Redirect to page 3 and abondon session</div>
</form>
</body>
</html>
第2页代码:
namespace SafariSessionProblem {
public partial class Page2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
lbl.Text = Session["TestVariable"].ToString();
}
}
}
第 3 页 HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div onclick="window.location = 'Page1.aspx'">Start over</div>
</form>
</body>
</html>
第 3 页代码:
namespace SafariSessionProblem {
public partial class Page3 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
Session.Abandon();
}
}
}
【问题讨论】:
-
我遇到了与 IOS6 会话变量类似的问题..
标签: ajax mobile-safari session-variables ios6