问题
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
回答1:
the problem may be the underscores in the domain. remove the _ and see if the same thing happens
回答2:
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"
来源:https://stackoverflow.com/questions/3658513/ie8-does-not-keep-session-variables