IE8不保留会话变量
如果我托管一个 ASP.NET 页面:
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void btn_Click(object sender, EventArgs e)
{
lbl.Text = HttpContext.Current.Session["a"] == null ?
"null" :
HttpContext.Current.Session["a"].ToString();
}
protected void btn_Click2(object sender, EventArgs e)
{
lbl.Text = HttpContext.Current.Cache["a"] == null ?
"null" :
HttpContext.Current.Cache["a"].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
HttpContext.Current.Session["a"] = "CBA";
lbl.Text = "assigned Session Variable";
HttpContext.Current.Cache.Add(
"a", "ABC", null,
DateTime.Now.AddHours(2), TimeSpan.Zero,
CacheItemPriority.NotRemovable, null);
}
}
</script>
<html>
<head>
<title>Testing Session</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btn" runat="server" Text="read Session" OnClick="btn_Click" />
<asp:Button ID="btn2" runat="server" Text="read Cache" OnClick="btn_Click2" />
<hr />
<asp:Label ID="lbl" runat="server" />
</div>
</form>
</body>
</html>
在第一次运行时,我确实获得了分配的会话变量
文本,但单击后,会话对象始终为null
Id,有一个选项我需要打开/关闭才能使用正常的会话变量?
在 IIS 6.0 和 Cassini(在 VS 2008 和 2010 下)上运行良好。
我开始不知道发生了什么:o(
非常感谢任何帮助!
上面示例页面的过程
更多测试表明这种情况仅发生在 IE 中(本例中为 ie8) case), Firefox, Safari, Opera, Chrome 他们都给出了正确的“答案”
检查情况截屏
If I host an ASP.NET page with:
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void btn_Click(object sender, EventArgs e)
{
lbl.Text = HttpContext.Current.Session["a"] == null ?
"null" :
HttpContext.Current.Session["a"].ToString();
}
protected void btn_Click2(object sender, EventArgs e)
{
lbl.Text = HttpContext.Current.Cache["a"] == null ?
"null" :
HttpContext.Current.Cache["a"].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
HttpContext.Current.Session["a"] = "CBA";
lbl.Text = "assigned Session Variable";
HttpContext.Current.Cache.Add(
"a", "ABC", null,
DateTime.Now.AddHours(2), TimeSpan.Zero,
CacheItemPriority.NotRemovable, null);
}
}
</script>
<html>
<head>
<title>Testing Session</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btn" runat="server" Text="read Session" OnClick="btn_Click" />
<asp:Button ID="btn2" runat="server" Text="read Cache" OnClick="btn_Click2" />
<hr />
<asp:Label ID="lbl" runat="server" />
</div>
</form>
</body>
</html>
on the first run I do get the assigned Session Variable
text, but upon click the Session object is always null
Id there an option I need to turn on/off to use the normal Session Variables ?
works fine on IIS 6.0 and Cassini (under VS 2008 and 2010).
I'm starting to be without ideas on what's going on :o(
Any help is greatly appreciated!
the process of the example page above
More tests shows that this only happens in IE (ie8 in this case), Firefox, Safari, Opera, Chrome they all give the correct "answer"
check the screen cast of the situation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能是域中的下划线。删除 _ 并查看是否发生同样的情况
the problem may be the underscores in the domain. remove the _ and see if the same thing happens
会话 ID 由浏览器通过本地存储的 cookie 进行维护。
您是否在某种保护模式下运行以阻止 IE8 存储 cookie?状态栏上应该有一个红色警告图标..“...阻止该网站存储 cookie”
Session ID's are maintained via a locally stored cookie by the browser.
Are you running in some sort of protected mode that prevents IE8 from storing cookies? There should be a red warning icon on the status bar.. something along the "...prevented this site from storing a cookie"